Skip to content

Commit 049ddb1

Browse files
committed
spin/charge loader for .txt file only
with `None` type converter
1 parent 80b18b4 commit 049ddb1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

qstack/spahm/rho/utils.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@
2121

2222

2323
def get_chsp(fname, n):
24-
if fname:
25-
chsp = np.loadtxt(fname, dtype=int, ndmin=1)
24+
def chsp_converter(chsp):
25+
if chsp == 'None':
26+
chsp = None
27+
else:
28+
chsp = int(chsp)
29+
return chsp
30+
if os.path.isfile(fname):
31+
chsp = np.loadtxt(fname, dtype=object, converters=chsp_converter, encoding=None)
2632
if(len(chsp)!=n):
2733
raise RuntimeError(f'Wrong lengh of the file {fname}')
2834
else:
29-
chsp = np.zeros(n, dtype=int)
35+
raise RuntimeError(f"{fname} can not be found")
3036
return chsp
3137

3238

tests/test_spahm_b.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ def test_ecp():
6262
def test_from_list():
6363
path = os.path.dirname(os.path.realpath(__file__))
6464
path2list = path+'/data/list_water.txt'
65+
path2spins = path+'/data/list_water_spins.txt'
66+
path2charges = path+'/data/list_water_charges.txt'
6567
xyzlist = utils.get_xyzlist(path2list)
66-
spins = utils.get_chsp(None, len(xyzlist))
67-
charges = utils.get_chsp(None, len(xyzlist))
68+
spins = utils.get_chsp(path2spins, len(xyzlist))
69+
charges = utils.get_chsp(path2charges, len(xyzlist))
6870
mols = utils.load_mols(xyzlist, charges, spins, 'minao', srcdir=path+'/data/')
6971
spahm_b = bond.get_repr(mols, xyzlist, 'LB', spin=spins, same_basis=True)
7072
Xtrue = np.load(path+'/data/list_H2O_spahm-b_minao_LB_alpha-beta.npy')

0 commit comments

Comments
 (0)