Skip to content

Commit e3a28d1

Browse files
committed
New hubbard format, cleanup, added assertions and nearest-neighbor functionality
1 parent 2a4e178 commit e3a28d1

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

nexus/examples/quantum_espresso/02_diamond_self_consistent_U/diamond_lda_sc_u.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# Other use examples
3535
# hubbard = {'V' : {('C-2p', 'C-2p'): [{'indices':(1,2), 'value':1e-8},
3636
# {'indices':(2,1), 'value':1e-8}]}}
37+
# hubbard = {'V' : {('C-2p', 'C-2p'): [{'radius' : 5.0, 'value':1e-8}]}} # radius is in units of Bohr
3738
# hubbard = {'U':{'C-2p': 1.0},
3839
# 'V':{('C-2p', 'C-2p'): 1e-8}}
3940
#end if

nexus/lib/pwscf_input.py

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,55 +1395,90 @@ def read_text(self, lines):
13951395
#end if
13961396
#end for
13971397
#end for
1398-
13991398
#end def read_text
14001399

14011400
def write_text(self):
14021401
manifold_dict = {}
14031402
contents = ''
14041403
for param, interaction in self.hubbard.items():
1404+
valid_format = True
1405+
assert(param in ['U', 'J', 'V'])
1406+
assert(isinstance(interaction, dict))
14051407
for label_manifold, value in interaction.items():
1406-
if not isinstance(label_manifold, tuple):
1407-
# Print U and J
1408+
if isinstance(label_manifold, str):
1409+
# Ex: {'U':{'C-2p': 1.0}}
1410+
assert(isinstance(value, (int, float)))
14081411
contents += f"{param} {label_manifold} {value} \n"
1409-
else:
1412+
elif isinstance(label_manifold, tuple):
14101413
assert(len(label_manifold) == 2)
1411-
if isinstance(value, float):
1414+
assert(all([isinstance(_, str) for _ in label_manifold]))
1415+
if isinstance(value, (int, float)):
1416+
# Ex: {'V' : {('C-2p', 'C-2p'): 1e-8}}
14121417
atom1, manifold1 = label_manifold[0].split('-')
14131418
atom2, manifold2 = label_manifold[1].split('-')
14141419
if atom1 not in manifold_dict.keys():
14151420
manifold_dict[atom1] = [manifold1]
14161421
elif manifold1 not in manifold_dict[atom1]:
14171422
manifold_dict[atom1].append(manifold1)
14181423
#end if
1419-
14201424
if atom2 not in manifold_dict.keys():
14211425
manifold_dict[atom2] = manifold2
14221426
elif manifold2 not in manifold_dict[atom2]:
14231427
manifold_dict[atom2].append(manifold2)
1424-
#end if
1425-
if isinstance(value, float):
1426-
elem = self.system.structure.elem
1427-
index1 = where(elem == atom1)[0] + 1
1428-
index2 = where(elem == atom2)[0] + 1
1429-
all_indices = unique(append(index1, index2))
1430-
combs = combinations(all_indices, 2)
1431-
print(all_indices)
1432-
for ind1, ind2 in combs:
1433-
contents += f"{param} {label_manifold[0]} {label_manifold[1]} {ind1} {ind2} {value}\n"
1428+
#end if
1429+
elem = self.system.structure.elem
1430+
index1 = where(elem == atom1)[0] + 1
1431+
index2 = where(elem == atom2)[0] + 1
1432+
combs = []
1433+
for in1 in index1:
1434+
for in2 in index2:
1435+
combs.append([in1, in2])
14341436
#end for
1437+
#end for
1438+
for ind1, ind2 in combs:
1439+
contents += f"{param} {label_manifold[0]} {label_manifold[1]} {ind1} {ind2} {value}\n"
1440+
#end for
14351441
elif isinstance(value, list):
14361442
for val in value:
1437-
ind1 = val['indices'][0]
1438-
ind2 = val['indices'][1]
1439-
val = val['value']
1440-
contents += f"{param} {label_manifold[0]} {label_manifold[1]} {ind1} {ind2} {val}\n"
1443+
if 'indices' in val.keys() and 'value' in val.keys():
1444+
# Ex: {'V' : {('C-2p', 'C-2p'): [{'indices':(1,2), 'value':1e-8}]}
1445+
ind1 = val['indices'][0]
1446+
ind2 = val['indices'][1]
1447+
val = val['value']
1448+
contents += f"{param} {label_manifold[0]} {label_manifold[1]} {ind1} {ind2} {val}\n"
1449+
elif 'radius' in val.keys() and 'value' in val.keys():
1450+
# Ex: {'V' : {('C-2p', 'C-2p'): [{'radius':4.5, 'value':1e-8}]} radius is in Bohr
1451+
atom1, manifold1 = label_manifold[0].split('-')
1452+
atom2, manifold2 = label_manifold[1].split('-')
1453+
elem = self.system.structure.elem
1454+
index1 = where(elem == atom1)[0]
1455+
index2 = where(elem == atom2)[0]
1456+
nn = self.system.structure.nearest_neighbors(rmax = val['radius'])
1457+
combs = []
1458+
for in1 in index1:
1459+
for in2 in index2:
1460+
if in2 in nn[in1]:
1461+
combs.append([in1, in2])
1462+
#end if
1463+
#end for
1464+
#end for
1465+
# import pdb
1466+
# pdb.set_trace()
1467+
for ind1, ind2 in combs:
1468+
contents += f"{param} {label_manifold[0]} {label_manifold[1]} {ind1} {ind2} {val['value']}\n"
1469+
#end for
1470+
else:
1471+
valid_format = False
14411472
#end if
14421473
#end for
14431474
else:
1444-
self.error('Hubbard card unknown input format')
1475+
valid_format = False
14451476
#end if
1477+
else:
1478+
valid_format = False
14461479
#end for
1480+
if not valid_format:
1481+
self.error('Hubbard card unknown input format')
14471482
#end for
14481483
#end for
14491484
for key, value in manifold_dict.items():
@@ -1454,7 +1489,8 @@ def write_text(self):
14541489
#end for
14551490
contents += '\n'
14561491
return contents
1457-
#end class occupations
1492+
#end def write_text
1493+
#end class hubbard
14581494

14591495

14601496

0 commit comments

Comments
 (0)