88PATH = os .path .dirname (os .path .realpath (__file__ ))
99
1010
11- def underlying_test (true_data_relpath , X ):
11+ def underlying_test (true_data_relpath , X , trim = False , only_z = None ):
1212 X_true = np .load (PATH + true_data_relpath , allow_pickle = True )
13- assert (X .shape == X_true .shape )
14- for a , a_true in zip (X , X_true , strict = True ):
15- assert (a [0 ] == a_true [0 ]) # atom type
16- assert (np .linalg .norm (a [1 ]- a_true [1 ]) < 1e-08 ) # atom representations
13+ if only_z is not None :
14+ X_true = X_true [np .isin (X_true [:,0 ], only_z )]
15+ assert X .shape == X_true .shape
16+ for (q , v ), (q_true , v_true ) in zip (X , X_true , strict = True ):
17+ assert q == q_true
18+ if trim is True :
19+ v = np .trim_zeros (v ) # short-version vectors should be trimmed
20+ assert np .allclose (v , v_true )
1721
1822
1923def test_water ():
@@ -26,8 +30,6 @@ def test_water():
2630
2731def test_water_alternate ():
2832 mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'minao' , charge = 0 , spin = None )
29- # X = atom.get_repr(mol, ["H", "O"], None, dm=None,
30- # guess='LB', model='lowdin-long-x', auxbasis='ccpvdzjkfit')
3133 X = atom .get_repr ("atom" , [mol ], [PATH ], 'LB' , spin = [None ], auxbasis = 'ccpvdzjkfit' , with_symbols = True )
3234 underlying_test ('/data/SPAHM_a_H2O/X_H2O.npy' , X )
3335
@@ -37,8 +39,7 @@ def test_water_lowdinshortx():
3739 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'LB' ,
3840 elements = ["H" , "O" ], spin = None , with_symbols = True ,
3941 model = 'lowdin-short-x' , auxbasis = 'ccpvdzjkfit' )
40- X = np .array ([(z ,np .trim_zeros (v )) for z ,v in X ], dtype = object ) # trimming is necessary to get the short-version vector !
41- underlying_test ('/data/SPAHM_a_H2O/X_H2O_lowdin-short-x.npy' , X )
42+ underlying_test ('/data/SPAHM_a_H2O/X_H2O_lowdin-short-x.npy' , X , trim = True )
4243
4344
4445def test_water_lowdinlong ():
@@ -54,75 +55,58 @@ def test_water_lowdinshort():
5455 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'LB' ,
5556 elements = ["H" , "O" ], spin = None , with_symbols = True ,
5657 model = 'lowdin-short' , auxbasis = 'ccpvdzjkfit' )
57- X = np .array ([(z ,np .trim_zeros (v )) for z ,v in X ], dtype = object ) # trimming is necessary to get the short-version vector !
58- underlying_test ('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy' , X )
58+ underlying_test ('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy' , X , trim = True )
5959
6060
6161def test_water_mr21 ():
6262 mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'minao' , charge = 0 , spin = None )
6363 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'LB' ,
6464 elements = ["H" , "O" ], spin = None , with_symbols = True ,
6565 model = 'MR2021' , auxbasis = 'ccpvdzjkfit' )
66- X = np .array ([(z ,np .trim_zeros (v )) for z ,v in X ], dtype = object ) # trimming is necessary to get the short-version vector !
67- underlying_test ('/data/SPAHM_a_H2O/X_H2O_MR2021.npy' , X )
66+ underlying_test ('/data/SPAHM_a_H2O/X_H2O_MR2021.npy' , X , trim = True )
6867
6968
7069def test_water_SAD_guess_open_shell ():
71- mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'sto3g' , charge = 1 , spin = 1 ) # test breaks when effective open-shell caluclation is needed
70+ mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'sto3g' , charge = 1 , spin = 1 )
7271 Xsad = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'sad' ,
7372 elements = ["H" , "O" ], spin = [1 ], with_symbols = True ,
7473 xc = 'hf' , model = 'sad-diff' , auxbasis = 'ccpvdzjkfit' )
7574 underlying_test ('/data/SPAHM_a_H2O/X_H2O-RC_SAD.npy' , Xsad )
7675
7776
7877def test_water_SAD_guess_close_shell ():
79- mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'sto3g' , charge = 0 , spin = 0 ) # test breaks when effective open-shell caluclation is needed
78+ mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'sto3g' , charge = 0 , spin = 0 )
8079 Xsad = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'sad' ,
8180 elements = ["H" , "O" ], spin = None , with_symbols = True ,
8281 xc = 'hf' , model = 'sad-diff' , auxbasis = 'ccpvdzjkfit' )
8382 underlying_test ('/data/SPAHM_a_H2O/X_H2O_SAD.npy' , Xsad )
8483
8584
8685def test_water_single_element ():
86+ only_z = ['O' ]
8787 mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'minao' , charge = 0 , spin = None )
8888 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'LB' ,
8989 elements = ["H" , "O" ], spin = None , with_symbols = True ,
90- model = 'lowdin-long-x' , auxbasis = 'ccpvdzjkfit' , only_z = ['O' ]) # requesting reps for O-atom only
91- X_true = np .load (PATH + '/data/SPAHM_a_H2O/X_H2O.npy' , allow_pickle = True )
92- # the next two lines deviate from the common template
93- a = X [0 ]
94- assert (X .shape == np .array (X_true [0 ], ndmin = 2 ).shape )
95- for a_true in X_true :
96- if a [0 ] == a_true [0 ]: # atom type
97- assert (np .linalg .norm (a [1 ]- a_true [1 ]) < 1e-08 ) # atom representations
90+ model = 'lowdin-long-x' , auxbasis = 'ccpvdzjkfit' , only_z = only_z )
91+ underlying_test ('/data/SPAHM_a_H2O/X_H2O.npy' , X , only_z = only_z )
9892
9993
10094def test_water_single_element_short ():
95+ only_z = ['O' ]
10196 mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'minao' , charge = 0 , spin = None )
10297 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'LB' ,
10398 elements = ["H" , "O" ], spin = None , with_symbols = True ,
104- model = 'lowdin-short' , auxbasis = 'ccpvdzjkfit' , only_z = ['O' ])
105- X = np .array ([(z ,np .trim_zeros (v )) for z ,v in X ], dtype = object ) # trimming is necessary to get the short-version vector !
106- X_true = np .load (PATH + '/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy' , allow_pickle = True )
107- a = X [0 ]
108- assert (X .shape == np .array (X_true [0 ], ndmin = 2 ).shape )
109- for a_true in X_true :
110- if a [0 ] == a_true [0 ]: # atom type
111- assert (np .linalg .norm (a [1 ]- a_true [1 ]) < 1e-08 ) # atom representations
99+ model = 'lowdin-short' , auxbasis = 'ccpvdzjkfit' , only_z = only_z )
100+ underlying_test ('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy' , X , only_z = only_z )
112101
113102
114103def test_water_single_element_SAD ():
104+ only_z = ['O' ]
115105 mol = compound .xyz_to_mol (PATH + '/data/H2O.xyz' , 'sto3g' , charge = 0 , spin = 0 )
116106 X = atom .get_repr ("atom" , [mol ], [PATH + '/data/H2O.xyz' ], 'sad' ,
117107 elements = ["H" , "O" ], spin = None , with_symbols = True ,
118- xc = 'hf' , model = 'sad-diff' , auxbasis = 'ccpvdzjkfit' , only_z = ['O' ])
119- X = np .array ([(z ,np .trim_zeros (v )) for z ,v in X ], dtype = object ) # trimming is necessary to get the short-version vector !
120- X_true = np .load (PATH + '/data/SPAHM_a_H2O/X_H2O_SAD.npy' , allow_pickle = True )
121- a = X [0 ]
122- assert (X .shape == np .array (X_true [0 ], ndmin = 2 ).shape )
123- for a_true in X_true :
124- if a [0 ] == a_true [0 ]: # atom type
125- assert (np .linalg .norm (a [1 ]- a_true [1 ]) < 1e-08 ) # atom representations
108+ xc = 'hf' , model = 'sad-diff' , auxbasis = 'ccpvdzjkfit' , only_z = only_z )
109+ underlying_test ('/data/SPAHM_a_H2O/X_H2O_SAD.npy' , X , only_z = only_z )
126110
127111
128112if __name__ == '__main__' :
0 commit comments