Skip to content

Commit

Permalink
spin/charge loader for .txt file only
Browse files Browse the repository at this point in the history
with `None` type converter
  • Loading branch information
YAY-C committed Dec 6, 2024
1 parent 80b18b4 commit 049ddb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions qstack/spahm/rho/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@


def get_chsp(fname, n):
if fname:
chsp = np.loadtxt(fname, dtype=int, ndmin=1)
def chsp_converter(chsp):
if chsp == 'None':
chsp = None
else:
chsp = int(chsp)
return chsp
if os.path.isfile(fname):
chsp = np.loadtxt(fname, dtype=object, converters=chsp_converter, encoding=None)
if(len(chsp)!=n):
raise RuntimeError(f'Wrong lengh of the file {fname}')
else:
chsp = np.zeros(n, dtype=int)
raise RuntimeError(f"{fname} can not be found")
return chsp


Expand Down
6 changes: 4 additions & 2 deletions tests/test_spahm_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def test_ecp():
def test_from_list():
path = os.path.dirname(os.path.realpath(__file__))
path2list = path+'/data/list_water.txt'
path2spins = path+'/data/list_water_spins.txt'
path2charges = path+'/data/list_water_charges.txt'
xyzlist = utils.get_xyzlist(path2list)
spins = utils.get_chsp(None, len(xyzlist))
charges = utils.get_chsp(None, len(xyzlist))
spins = utils.get_chsp(path2spins, len(xyzlist))
charges = utils.get_chsp(path2charges, len(xyzlist))
mols = utils.load_mols(xyzlist, charges, spins, 'minao', srcdir=path+'/data/')
spahm_b = bond.get_repr(mols, xyzlist, 'LB', spin=spins, same_basis=True)
Xtrue = np.load(path+'/data/list_H2O_spahm-b_minao_LB_alpha-beta.npy')
Expand Down

0 comments on commit 049ddb1

Please sign in to comment.