Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line calculations errors for one-dimensional graphene nanoribbons #113

Open
ybfu opened this issue May 24, 2021 · 18 comments
Open

Line calculations errors for one-dimensional graphene nanoribbons #113

ybfu opened this issue May 24, 2021 · 18 comments

Comments

@ybfu
Copy link

ybfu commented May 24, 2021

Hi,

Recently I am using the Z2pack to calculate Z2 invariant for one-dimensional graphene nanoribbons. I chose a literature-reported GNR (7-armchair GNR, Phys. Rev. Lett. 2017, 119, 076401, Z2=1). Before this, I tried the sample calculation for Bi and it is successful. However, when I tried the line calculations for the GNR, there was an error.

Here is the input file:

import os
import shutil
import subprocess

import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET

import z2pack

qedir = "{0}/bin".format(os.getenv('EBROOTQUANTUMESPRESSO'))
wandir = "{0}/bin".format(os.getenv('EBROOTWANNIER90'))

mpirun = 'mpirun -np 20 '
pwcmd = mpirun + qedir + '/pw.x '
pw2wancmd = mpirun + qedir + '/pw2wannier90.x '
wancmd = wandir + '/wannier90.x'

z2cmd = (
wancmd + ' 7AGNR -pp;' + pwcmd + '< 7AGNR.nscf.in >& pw.log;' + pw2wancmd +
'< 7AGNR.pw2wan.in >& pw2wan.log;'
)

if not os.path.exists('./plots'):
os.mkdir('./plots')
if not os.path.exists('./results'):
os.mkdir('./results')
if not os.path.exists('./scf'):
os.makedirs('./scf')
print("Running the scf calculation")
shutil.copyfile('input/7AGNR.scf.in', 'scf/7AGNR.scf.in')
subprocess.call(pwcmd + ' < 7AGNR.scf.in > scf.out', shell=True, cwd='./scf')

cell = ET.parse('scf/7AGNR.xml').find('output').find('atomic_structure'
).find('cell')
unit = cell.get('unit', 'Bohr')
lattice = '\n'.join([cell.find(vec).text for vec in ['a1', 'a2', 'a3']])

with open('input/tpl_7AGNR.win', 'r') as f:
tpl_7AGNR_win = f.read()
with open('input/7AGNR.win', 'w') as f:
f.write(tpl_7AGNR_win.format(unit=unit, lattice=lattice))

input_files = [
'input/' + name for name in ["7AGNR.nscf.in", "7AGNR.pw2wan.in", "7AGNR.win"]
]
system = z2pack.fp.System(
input_files=input_files,
kpt_fct=[z2pack.fp.kpoint.qe, z2pack.fp.kpoint.wannier90_full],
kpt_path=["7AGNR.nscf.in", "7AGNR.win"],
command=z2cmd,
executable='/bin/bash',
mmn_path='7AGNR.mmn'
)

result_0 = z2pack.line.run(
system=system,
line=lambda t: [t, 0, 0],
save_file='./results/res_0.json',
load=True
)

fig, ax = plt.subplots(1, 2, sharey=True, figsize=(9, 5))
z2pack.plot.wcc(result_0, axis=ax[0])
plt.savefig('plots/plot.pdf', bbox_inches='tight')

print(
'Z2 topological invariant at kx = 0: {0}'.format(
z2pack.invariant.z2(result_0)
)
)

The error is like this:
+----------------------------------------------------------------------+
|================ |
|LINE CALCULATION |
|================ |
|starting at 2021-05-24 18:26:56,442 |
|running Z2Pack version 2.2.0 |
| |
|init_result: None |
|iterator: range(8, 27, 2) |
|line: <function at 0x7f740ba82290> |
|load: True |
|load_quiet: True |
|pos_tol: 0.01 |
|save_file: ./results/res_0.json |
|serializer: auto |
|system: <z2pack.fp._first_principl<...> object at 0x7f73fcc5fd90>|
+----------------------------------------------------------------------+

INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 8
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 10
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 12
INFO: Saving line result to file ./results/res_0.json
INFO: 1 of 1 line convergence criteria fulfilled.

+----------------------------------------------------------------------+
| Calculation finished in 0h 6m 52s |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| ================== |
| CONVERGENCE REPORT |
| ================== |
| |
| PosCheck: PASSED |
+----------------------------------------------------------------------+
Traceback (most recent call last):
File "run.py", line 75, in
z2pack.plot.wcc(result_0, axis=ax[0])
File "</sw/installed/Python/3.7.4-GCCcore-8.3.0/lib/python3.7/site-packages/de corator.py:decorator-gen-30>", line 2, in wcc
File "/home/yfu/.local/lib/python3.7/site-packages/z2pack/plot.py", line 36, i n inner
func(data, axis=axis, **kwargs)
File "/home/yfu/.local/lib/python3.7/site-packages/z2pack/plot.py", line 169, in wcc
_plot_gaps(surface_result, axis=axis, gaps=gaps, gap_settings=gap_settings)
File "/home/yfu/.local/lib/python3.7/site-packages/z2pack/plot.py", line 48, i n _plot_gaps
surface_result.t,
File "/home/yfu/.local/lib/python3.7/site-packages/z2pack/_result.py", line 35 , in getattr
return getattr(self.data, name)
File "/home/yfu/.local/lib/python3.7/site-packages/fsc/locker/_locker.py", lin e 45, in inner
return fct(self, key)
File "/home/yfu/.local/lib/python3.7/site-packages/z2pack/line/_data.py", line 70, in getattr
return super().getattribute(name)
AttributeError: 'OverlapLineData' object has no attribute 't'

It mentioned that an attribute reference or assignment fails. Looks like the 't' is not defined. Another strange thing is that the PosCheck is passed but no other detailed information. There is no error in the scf and nscf calculation tasks. I also checked the internet but didn't find a similar error. That is strange.

@greschd
Copy link
Member

greschd commented May 25, 2021

The reason for this error is that the plot.wcc utility (and the other plot and invariant helpers) work only with surface results, not line results. I guess this could produce a nicer error..

As for inspecting the results of your calculation, since it is a 1D calculation it will have only a single set of WCC, or one sum of WCC. You can access the WCC as

print(result_0.wcc)

or the sum of WCC as

print(result_0.pol)

I'm not intimately familiar with the GNR paper, but suspect it's a different kind of Z2 invariant to the Kane-Mele one. One possibility is that the sum of WCC is quantized to be either 0 or 0.5, which also produces a Z2 invariant.

@ybfu
Copy link
Author

ybfu commented May 25, 2021

Thank you for the solution. I deleted the plot part and printed the WCC result directly. The tasks are running successfully and I got the following results:

For the first GNR:
+----------------------------------------------------------------------+
|================ |
|LINE CALCULATION |
|================ |
|starting at 2021-05-25 10:15:37,228 |
|running Z2Pack version 2.2.0 |
| |
|init_result: None |
|iterator: range(8, 27, 2) |
|line: <function at 0x7f0f021a6e60> |
|load: True |
|load_quiet: True |
|pos_tol: 0.01 |
|save_file: ./results/res_0.json |
|serializer: auto |
|system: <z2pack.fp._first_principl<...> object at 0x7f0ed4e82ad0>|
+----------------------------------------------------------------------+

INFO: Saving line result to file ./results/res_0.json
INFO: 1 of 1 line convergence criteria fulfilled.

+----------------------------------------------------------------------+
| Calculation finished in 0h 0m 1s |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| ================== |
| CONVERGENCE REPORT |
| ================== |
| |
| PosCheck: PASSED |
+----------------------------------------------------------------------+
[0.10688534774679626, 0.10688543862570214, 0.19715876920685, 0.1971587695030033, 0.20608812788399428, 0.20608812842119562, 0.24284867889269304, 0.24284868637749 14, 0.28920615940591016, 0.28920615959490875, 0.3131467429846619, 0.313146746136 02944, 0.324270578192647, 0.3242705784553992, 0.4953883362653025, 0.495388336667 3999, 0.49539016877727327, 0.49539016878349146, 0.4954229119824666, 0.4954229122 312385, 0.4962704106392736, 0.4962704417507652, 0.6665499152108258, 0.6665499152 231716, 0.6777940785061525, 0.6777940825778864, 0.7013031777777318, 0.7013031781 295902, 0.7477619271986414, 0.7477619346545792, 0.7846949947340155, 0.7846949948 117543, 0.7935625303778626, 0.7935625304434732, 0.995010645875945, 0.99501064878 44013, 0.9950706019991764, 0.9950706020656601, 0.9953761112208728, 0.99537611159 63989]
0.03840057971263633

For the second GNR:
+----------------------------------------------------------------------+
|================ |
|LINE CALCULATION |
|================ |
|starting at 2021-05-25 11:39:42,749 |
|running Z2Pack version 2.2.0 |
| |
|init_result: None |
|iterator: range(8, 27, 2) |
|line: <function at 0x7f7ec72e9e60> |
|load: True |
|load_quiet: True |
|pos_tol: 0.01 |
|save_file: ./results/res_0.json |
|serializer: auto |
|system: <z2pack.fp._first_principl<...> object at 0x7f7eb088bf10>|
+----------------------------------------------------------------------+

INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 8
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 10
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 12
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 14
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 16
INFO: Saving line result to file ./results/res_0.json
INFO: 0 of 1 line convergence criteria fulfilled.
INFO: Calculating line for N = 18
INFO: Saving line result to file ./results/res_0.json
INFO: 1 of 1 line convergence criteria fulfilled.

+----------------------------------------------------------------------+
| Calculation finished in 0h 16m 37s |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| ================== |
| CONVERGENCE REPORT |
| ================== |
| |
| PosCheck: PASSED |
+----------------------------------------------------------------------+
[0.17296473069906157, 0.17296473093237436, 0.17908280517561787, 0.17908281017815 272, 0.19757941352489336, 0.19757941567072088, 0.24459751220930265, 0.2445975124 677249, 0.2898908384710595, 0.28989083861884773, 0.2982912132033475, 0.298291214 28242755, 0.49625217007761574, 0.4962524818404543, 0.4997176129269368, 0.4997176 134817113, 0.4997331458813255, 0.49973314618376413, 0.49974600658131996, 0.49974 60068581518, 0.7012065223092954, 0.7012065248760129, 0.7096160594302663, 0.70961 60595235359, 0.7548957155594915, 0.754895715649857, 0.8019195374625285, 0.801919 5387849714, 0.8204158612342494, 0.8204158637067835, 0.8265408226884187, 0.826540 8230750572, 0.9954701942487686, 0.9954705344722173, 0.9997449786822606, 0.999744 9792651143, 0.9997520496317563, 0.9997520497057493, 0.9997528384777475, 0.999752 8386739006]
0.9743407267227866

Accordingly, the sum of WCC for the first and second one is 0.0384 and 0.974, respectively. However, according to the literature (Phys. Rev. Lett. 2017, 119, 076401), the Z2 invariant for the first one and second one should be 1 and 0. That makes me confused. Is it because of the unit cell of the GNR structures or other problems about scf/nscf calculations?

@greschd
Copy link
Member

greschd commented May 25, 2021

Looking at the literature you refer to, the sum of WCC should be either 0 or 0.5 (because Z2Pack normalizes the values to 1; this corresponds to the 0 or pi values of the paper). This quantization of the sum of WCC is not universal, but enforced by symmetry.

So there are a few things that could go wrong here:

  • maybe the number of bands used is not exactly the desired occupied subspace
  • maybe the calculation does not include / enforce the desired symmetry
  • convergence issues: if the band gap of the system is very small, it's possible that Z2Pack doesn't detect non-convergence (because the value only starts changing at very small spacing). In that case, you can increase the values of the iterator input.

@ybfu
Copy link
Author

ybfu commented May 25, 2021

Thank you for the reply. Regarding your suggestions, I repeated several calculation tasks. However, there are still many problems.

  1. For the number of used bands I changed the values of num_wann, num_bands, and exclude_bands in the tpl_7AGNR.win file. However, in some values, the PW2WANNIER task will report a very strange error which I cannot find a solution. In some cases, the PosCheck will fail. That makes me very confused.

  2. You mentioned that the calculation needs to include the desired symmetry. Does it mean some parameter setting in the scf and nscf calculations?

  3. The bandgap of the two GNRs is about 2 eV. So the convergence should not be the problem, is it right?

So would you mind helping me to check these GNRs? I can send the cif files to your e-mail. Thank you very much in advance.

@greschd
Copy link
Member

greschd commented May 29, 2021

1. For the number of used bands I changed the values of num_wann, num_bands, and exclude_bands in the tpl_7AGNR.win file. However, in some values, the PW2WANNIER task will report a very strange error which I cannot find a solution. In some cases, the  PosCheck will fail.  That makes me very confused.

It's completely expected that the calculation wouldn't work for arbitrary num_wann, num_bands and exclude_bands. The Wannier charge centers are well-defined only when the wave functions span a smooth manifold. Most commonly, this means that we require a direct band gap between bands that are included and the excluded ones. Details on this can be found in the Z2Pack book chapter.

2. You mentioned that the calculation needs to include the desired symmetry. Does it mean some parameter setting in the scf and nscf calculations?

This depends on the DFT code. For Quantum ESPRESSO, symmetries are usually determined automatically if the input structure includes them (QE will report the symmetries it uses).

3. The bandgap of the two GNRs is about 2 eV. So the convergence should not be the problem, is it right?

Yes, that should be unproblematic.

So would you mind helping me to check these GNRs? I can send the cif files to your e-mail. Thank you very much in advance.

No, I don't generally offer this level of support outside of paid consultancy.

@ybfu
Copy link
Author

ybfu commented May 31, 2021

Thank you very much for your reply. It is really helpful and important for me. In recent days I have carefully read the Z2Pack book chapter and learned a lot. Now the PW2WANNIER tasks can run successfully. I fully understand that you cannot provide us the results checking. But I still have some questions, maybe you can give me some suggestions.

  1. For the error of the PW2WANNIER tasks I think it was caused by the incorrect number of nband in nscf file. The total electrons of my GNR are 60. Previously I always set the nband to 30. Now I noticed the fact that I used noncolin = .true. and lspinorb = .true. in scf and nscf calculation, which means that there will be 60 occupied bands. Then I changed the nbnd to 70 and there will be no problem.

  2. However, the sum of WCC is quite strange. When I set the num_wann, num_bands, and exclude_bands in the tpl_7AGNR.win to 64, 64, and 65-67. The PosCheck will be successful and the sum of WCC is 0.98. Since this GNR is a topological trivial GNR the sum of WCC should be 0, correct? Then I tried other values of num_wann, num_bands, and exclude_bands to 63/63/64-70 and 65/65/66-70, the PosCheck failed and the sum of WCC will be 0.92/0.73. Such problems make me quite confused. Since the highest occupied band is the 60th band and there is a direct bandgap for this GNR, there should be no such errors.

Thank you very much in advance.

@greschd
Copy link
Member

greschd commented May 31, 2021

If there are 60 occupied bands, you should set num_wann and num_bands in the Wannier90 input to 60, and exclude_bands to 61-<number of bands in the NSCF>.

In other words, the Wannier90 calculation should be set up such that only the desired target bands are included in the calculation.

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

Thank you for the quick reply. I tried to set the num_wann, num_bands, and exclude_bands in the tpl_7AGNR.win to 60, 60, and 61-70. But the results are still. For the trivial and non-trivial GNR, the sum of WCC is 0.98 and 0.72, respectively. Strange to me.

@greschd
Copy link
Member

greschd commented Jun 1, 2021

As a quick check, can you confirm that the number of WCC that are computed is also 60?

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

Here is the one printout result. The number of calculated WCC is 60. Looks like no problem.

[0.2063925948242325, 0.20639259523895023, 0.20928816237869502, 0.209288163927576 8, 0.21948308711423192, 0.2194830875517462, 0.23648234583352906, 0.2364823467243 4448, 0.24580792366736018, 0.2458079237875878, 0.24919258456866117, 0.2491925847 303124, 0.2561563424732872, 0.2561563433412845, 0.27231891210653736, 0.272318913 29794133, 0.28376336246632045, 0.28376336300899885, 0.2913146204226991, 0.291314 62084898024, 0.4997547021251558, 0.49975470230794966, 0.4997551607401317, 0.4997 5516082438437, 0.4997560342472227, 0.49975603437820487, 0.49975647977909204, 0.4 9975648021870156, 0.7081953773806977, 0.7081953782281507, 0.7157503861296426, 0. 715750386608657, 0.7271972107177532, 0.7271972115593123, 0.7433607590692674, 0.7 4336075955244, 0.7503171896410243, 0.7503171898511077, 0.7537053193964363, 0.753 7053194654937, 0.7630346653148834, 0.7630346663509845, 0.780032624245808, 0.7800 326243922309, 0.7902281071849484, 0.7902281077967196, 0.7931202722321626, 0.7931 202729287846, 0.9996652243930915, 0.9996652246297503, 0.9997544805832227, 0.9997 544809966081, 0.9997546504611944, 0.9997546511471436, 0.9997575068376133, 0.9997 575069004614, 0.9997594413006938, 0.9997594416667294, 0.9998538151193439, 0.9998 538158315038]

@greschd
Copy link
Member

greschd commented Jun 1, 2021

Have you tested what happens when you reduce pos_tol? The default value (0.01) tests for the change in position of individual WCC - after summation it could still have a significant error.

@greschd
Copy link
Member

greschd commented Jun 1, 2021

The next step in approaching this problem would be understanding exactly which symmetry should force the sum of WCC to be either 0 or 0.5, and see how this fails. For example, should there be pairs of WCC whose value have a certain relation?

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

Have you tested what happens when you reduce pos_tol? The default value (0.01) tests for the change in position of individual WCC - after summation it could still have a significant error.

I tried to reduce the 'pos_tol' to 0.005 and 0.001 while the sum of WCC is 0.98 as the previous results.

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

The next step in approaching this problem would be understanding exactly which symmetry should force the sum of WCC to be either 0 or 0.5, and see how this fails. For example, should there be pairs of WCC whose value have a certain relation?

So you mean to check the coordination of each wannier center? This I didn't try before. Could you give more details about this? Thank you very much in advance.

@greschd
Copy link
Member

greschd commented Jun 1, 2021

So you mean to check the coordination of each wannier center? This I didn't try before. Could you give more details about this? Thank you very much in advance.

What is the symmetry that should enforce the sum of WCC to be 0 or 0.5 here? The symmetry should have some effect in terms of individual WCC. If you can see how it is broken, it might help figuring out the problem as a whole.

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

So you mean to check the coordination of each wannier center? This I didn't try before. Could you give more details about this? Thank you very much in advance.

What is the symmetry that should enforce the sum of WCC to be 0 or 0.5 here? The symmetry should have some effect in terms of individual WCC. If you can see how it is broken, it might help figuring out the problem as a whole.

Thank you for the quick reply. Regarding the symmetry, do you mean the symmetry for the unit cell such as mirror/inverse symmetry? In this work (https://pubs.acs.org/doi/abs/10.1021/acs.nanolett.8b03416), they draw the WCC for the GNR. But I don't know how to do it right now. Can you recommend some literature about this?

@greschd
Copy link
Member

greschd commented Jun 1, 2021

In the absence of (spatial or time-reversal) symmetries, the sum of WCC can have any value. For it to be quantized, there must be some symmetry that acts in a way that only these two values are allowed.

For example in https://journals.aps.org/prb/abstract/10.1103/PhysRevB.83.235401, it is time-reversal symmetry that forces the WCC on time-reversal invariant lines to come in pairs.

@ybfu
Copy link
Author

ybfu commented Jun 1, 2021

Thanks for the quick reply. I will check the literature tomorrow and check my system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants