@@ -1395,55 +1395,90 @@ def read_text(self, lines):
1395
1395
#end if
1396
1396
#end for
1397
1397
#end for
1398
-
1399
1398
#end def read_text
1400
1399
1401
1400
def write_text (self ):
1402
1401
manifold_dict = {}
1403
1402
contents = ''
1404
1403
for param , interaction in self .hubbard .items ():
1404
+ valid_format = True
1405
+ assert (param in ['U' , 'J' , 'V' ])
1406
+ assert (isinstance (interaction , dict ))
1405
1407
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 )))
1408
1411
contents += f"{ param } { label_manifold } { value } \n "
1409
- else :
1412
+ elif isinstance ( label_manifold , tuple ) :
1410
1413
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}}
1412
1417
atom1 , manifold1 = label_manifold [0 ].split ('-' )
1413
1418
atom2 , manifold2 = label_manifold [1 ].split ('-' )
1414
1419
if atom1 not in manifold_dict .keys ():
1415
1420
manifold_dict [atom1 ] = [manifold1 ]
1416
1421
elif manifold1 not in manifold_dict [atom1 ]:
1417
1422
manifold_dict [atom1 ].append (manifold1 )
1418
1423
#end if
1419
-
1420
1424
if atom2 not in manifold_dict .keys ():
1421
1425
manifold_dict [atom2 ] = manifold2
1422
1426
elif manifold2 not in manifold_dict [atom2 ]:
1423
1427
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 ])
1434
1436
#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
1435
1441
elif isinstance (value , list ):
1436
1442
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
1441
1472
#end if
1442
1473
#end for
1443
1474
else :
1444
- self . error ( 'Hubbard card unknown input format' )
1475
+ valid_format = False
1445
1476
#end if
1477
+ else :
1478
+ valid_format = False
1446
1479
#end for
1480
+ if not valid_format :
1481
+ self .error ('Hubbard card unknown input format' )
1447
1482
#end for
1448
1483
#end for
1449
1484
for key , value in manifold_dict .items ():
@@ -1454,7 +1489,8 @@ def write_text(self):
1454
1489
#end for
1455
1490
contents += '\n '
1456
1491
return contents
1457
- #end class occupations
1492
+ #end def write_text
1493
+ #end class hubbard
1458
1494
1459
1495
1460
1496
0 commit comments