Skip to content

Commit 69759f8

Browse files
committed
f! tsts
1 parent ae4aca5 commit 69759f8

1 file changed

Lines changed: 117 additions & 28 deletions

File tree

arc/job/adapters/ts/linear_test.py

Lines changed: 117 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
import shutil
1010
import unittest
1111

12+
from rmgpy.data.kinetics import KineticsFamily
13+
1214
from arc.common import ARC_PATH, almost_equal_coords
1315
from arc.job.adapters.ts.linear import (LinearAdapter,
1416
average_zmat_params,
17+
get_r_constraints,
1518
get_rxn_weight,
1619
get_weight,
1720
interpolate_isomerization,
1821
)
1922
from arc.reaction import ARCReaction
2023
from arc.rmgdb import make_rmg_database_object, load_families_only
21-
from arc.species.converter import str_to_xyz
24+
from arc.species.converter import str_to_xyz, xyz_to_str
2225
from arc.species.species import ARCSpecies
2326
from arc.species.zmat import _compare_zmats
2427

@@ -73,6 +76,30 @@ def setUpClass(cls):
7376
H 1.36205133 -3.75009763 -2.57288841""")])
7477
cls.rxn_1.determine_family(rmg_database=cls.rmgdb)
7578

79+
cls.rxn_2 = ARCReaction(r_species=[ARCSpecies(label='CCONO', smiles='CCON=O',
80+
xyz="""C -1.36894499 0.07118059 -0.24801399
81+
C -0.01369535 0.17184136 0.42591278
82+
O -0.03967083 -0.62462610 1.60609048
83+
N 1.23538512 -0.53558048 2.24863846
84+
O 1.25629155 -1.21389295 3.27993827
85+
H -2.16063255 0.41812452 0.42429392
86+
H -1.39509985 0.66980796 -1.16284741
87+
H -1.59800183 -0.96960842 -0.49986392
88+
H 0.19191326 1.21800574 0.68271847
89+
H 0.76371340 -0.19234475 -0.25650067""")],
90+
p_species=[ARCSpecies(label='CCNO2', smiles='CC[N+](=O)[O-]',
91+
xyz="""C -1.12362739 -0.04664655 -0.08575959
92+
C 0.24488022 -0.51587553 0.36119196
93+
N 0.57726975 -1.77875156 -0.37104243
94+
O 1.16476543 -1.66382529 -1.45384186
95+
O 0.24561669 -2.84385320 0.16410116
96+
H -1.87655344 -0.80826847 0.13962125
97+
H -1.14729169 0.14493421 -1.16405294
98+
H -1.41423043 0.87863077 0.42354512
99+
H 1.02430791 0.21530309 0.12674144
100+
H 0.27058353 -0.73979548 1.43184405""")])
101+
cls.rxn_2.determine_family(rmg_database=cls.rmgdb)
102+
76103
def test_average_zmat_params(self):
77104
"""Test the average_zmat_params() function."""
78105
zmat_1 = {'symbols': ('H', 'H'),
@@ -166,8 +193,8 @@ def test_get_rxn_weight(self):
166193
rxn_1.ts_species.e0 = 391.6
167194
self.assertAlmostEquals(get_rxn_weight(rxn_1), 0.3417832)
168195

169-
def test_interpolate_isomerization(self):
170-
"""Test the interpolate_isomerization() function."""
196+
def test_interpolate_isomerization_intra_h_migration(self):
197+
"""Test the interpolate_isomerization() function for intra H migration reactions."""
171198
nc3h7_xyz = """C 0.00375165 -0.48895802 -1.20586379
172199
C 0.00375165 -0.48895802 0.28487510
173200
C 0.00375165 0.91997987 0.85403684
@@ -191,36 +218,76 @@ def test_interpolate_isomerization(self):
191218
nc3h7 = ARCSpecies(label='nC3H7', smiles='[CH2]CC', xyz=nc3h7_xyz)
192219
ic3h7 = ARCSpecies(label='iC3H7', smiles='C[CH]C', xyz=ic3h7_xyz)
193220
rxn = ARCReaction(r_species=[nc3h7], p_species=[ic3h7])
194-
expected_ts_xyz = str_to_xyz("""C 0.01099731 -0.46789926 -1.15958911
195-
C 0.01099731 -0.46789926 0.33114978
196-
C 0.01099731 0.94103865 0.90031155
197-
H 0.57795661 -1.24174248 -1.65467180
198-
H -0.39690222 0.34527841 -1.69240298
199-
H -1.19440431 -1.28933062 -0.47327539
200-
H 0.89689057 -1.16420498 0.45967951
201-
H 0.76979130 1.33747945 0.33815513
202-
H -0.04544494 0.70455273 1.77835334
203-
H -1.00071642 1.24557408 0.38839197""")
204-
ts_xyz = interpolate_isomerization(rxn, use_weights=False)
205-
self.assertTrue(almost_equal_coords(ts_xyz, expected_ts_xyz))
221+
expected_ts_xyz = str_to_xyz("""C 0.00598652 -0.48762088 -1.18600054
222+
C 0.00598652 -0.48762088 0.30473835
223+
C 0.00598652 0.92131703 0.87390011
224+
H 0.57807817 -1.25594905 -1.69382911
225+
H -0.42698663 0.35443110 -1.71434916
226+
H -1.27461406 -1.27709743 -0.24121083
227+
H 0.89172104 -1.02331658 0.66282944
228+
H 0.88735917 1.48171935 0.54398704
229+
H 0.01673891 0.88717852 1.96803717
230+
H -0.88613815 1.47510670 0.56219446""")
231+
ts_xyzs = interpolate_isomerization(rxn, use_weights=False)
232+
self.assertEqual(len(ts_xyzs), 2)
233+
self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
206234

207235
nc3h7.e0 = 101.55
208236
ic3h7.e0 = 88.91
209237
ts = ARCSpecies(label='TS', is_ts=True, multiplicity=2, xyz=expected_ts_xyz)
210238
ts.e0 = 105
211239
rxn.ts_species = ts
212-
expected_ts_xyz = str_to_xyz("""C 0.01224420 -0.47400672 -1.18787451
213-
C 0.01224420 -0.47400672 0.30286438
214-
C 0.01224420 0.93493122 0.87202615
215-
H 0.47981756 -1.29923732 -1.70742021
216-
H -0.50470551 0.28201158 -1.73526026
217-
H -1.06475721 -1.18141451 0.26785378
218-
H 0.86736552 -1.12118386 0.54383845
219-
H 0.79813573 1.38347069 0.43772483
220-
H -0.03897336 0.76031233 1.86961141
221-
H -0.97425159 1.33180895 0.47825005""")
222-
ts_xyz = interpolate_isomerization(rxn, use_weights=True)
223-
self.assertTrue(almost_equal_coords(ts_xyz, expected_ts_xyz))
240+
expected_ts_xyz = str_to_xyz("""C 0.00591772 -0.48764618 -1.20069282
241+
C 0.00591772 -0.48764618 0.29004607
242+
C 0.00591772 0.92129176 0.85920784
243+
H 0.47693974 -1.30982443 -1.72763512
244+
H -0.52424330 0.28530048 -1.74580953
245+
H -1.07348606 -1.15308709 0.40763997
246+
H 0.89165221 -1.02334186 0.64813718
247+
H 0.88729039 1.48169408 0.52929476
248+
H 0.01667012 0.88715326 1.95334482
249+
H -0.88620694 1.47508143 0.54750218""")
250+
ts_xyzs = interpolate_isomerization(rxn, use_weights=True)
251+
self.assertEqual(len(ts_xyzs), 2)
252+
self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
253+
254+
# r_xyz = """C -1.05582103 -0.03329574 -0.10080257
255+
# C 0.41792695 0.17831205 0.21035514
256+
# O 1.19234020 -0.65389683 -0.61111443
257+
# O 2.44749684 -0.41401220 -0.28381363
258+
# H -1.33614002 -1.09151783 0.08714882
259+
# H -1.25953618 0.21489046 -1.16411897
260+
# H -1.67410396 0.62341419 0.54699514
261+
# H 0.59566350 -0.06437686 1.28256640
262+
# H 0.67254676 1.24676329 0.02676370"""
263+
# p_xyz = """C -1.40886397 0.22567351 -0.37379668
264+
# C 0.06280787 0.04097694 -0.38515682
265+
# O 0.44130326 -0.57668419 0.84260864
266+
# O 1.89519755 -0.66754203 0.80966180
267+
# H -1.87218376 0.90693511 -1.07582340
268+
# H -2.03646287 -0.44342165 0.20255768
269+
# H 0.35571681 -0.60165457 -1.22096147
270+
# H 0.56095122 1.01161503 -0.47393734
271+
# H 2.05354047 -0.10415729 1.58865243"""
272+
# r = ARCSpecies(label='R', smiles='CCO[O]', xyz=r_xyz)
273+
# p = ARCSpecies(label='P', smiles='[CH2]COO', xyz=p_xyz)
274+
# rxn = ARCReaction(r_species=[r], p_species=[p])
275+
# expected_ts_xyz = str_to_xyz("""C 0.00598652 -0.48762088 -1.18600054
276+
# C 0.00598652 -0.48762088 0.30473835
277+
# C 0.00598652 0.92131703 0.87390011
278+
# H 0.57807817 -1.25594905 -1.69382911
279+
# H -0.42698663 0.35443110 -1.71434916
280+
# H -1.27461406 -1.27709743 -0.24121083
281+
# H 0.89172104 -1.02331658 0.66282944
282+
# H 0.88735917 1.48171935 0.54398704
283+
# H 0.01673891 0.88717852 1.96803717
284+
# H -0.88613815 1.47510670 0.56219446""")
285+
# ts_xyzs = interpolate_isomerization(rxn, use_weights=False)
286+
# self.assertEqual(len(ts_xyzs), 3)
287+
# for ts_xyz in ts_xyzs:
288+
# print(f'\nTS xyz:\n\n')
289+
# print(xyz_to_str(ts_xyz))
290+
# self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
224291

225292
def test_linear_adapter(self):
226293
"""Test the LinearAdapter class."""
@@ -229,14 +296,36 @@ def test_linear_adapter(self):
229296
reactions=[self.rxn_1],
230297
testing=True,
231298
project='test',
232-
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_linear', 'tst1'),
299+
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_linear', 'rxn_1'),
233300
)
234301
self.assertIsNone(self.rxn_1.ts_species)
235302
linear_1.execute()
236303
self.assertEqual(len(self.rxn_1.ts_species.ts_guesses), 1)
237304
self.assertEqual(self.rxn_1.ts_species.ts_guesses[0].initial_xyz['symbols'],
238305
('C', 'C', 'C', 'C', 'C', 'H', 'H', 'H', 'H', 'H', 'H'))
239306

307+
def test_linear_adapter_2(self):
308+
self.rxn_2.family = KineticsFamily(label='intra_NO2_ONO_conversion')
309+
self.rxn_2.atom_map = [0, 1, 3, 2, 4, 5, 7, 6, 9, 8]
310+
self.assertEqual(self.rxn_2.family.label, 'intra_NO2_ONO_conversion')
311+
linear_2 = LinearAdapter(job_type='tsg',
312+
reactions=[self.rxn_2],
313+
testing=True,
314+
project='test',
315+
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_linear', 'rxn_2'),
316+
)
317+
self.assertIsNone(self.rxn_2.ts_species)
318+
linear_2.execute()
319+
self.assertEqual(len(self.rxn_2.ts_species.ts_guesses), 1)
320+
print(xyz_to_str(self.rxn_2.ts_species.ts_guesses[0].initial_xyz))
321+
self.assertEqual(self.rxn_2.ts_species.ts_guesses[0].initial_xyz['symbols'],
322+
('C', 'C', 'C', 'C', 'C', 'H', 'H', 'H', 'H', 'H', 'H'))
323+
324+
def test_get_r_constraints(self):
325+
"""Test the get_r_constraints() function."""
326+
self.assertEqual(get_r_constraints([(1, 5)], [(0, 5)]), {'R_atom': [(5, 1)]})
327+
self.assertEqual(get_r_constraints([(1, 5), (7, 2), (8, 2)], [(0, 5), (7, 4), (8, 1)]), {'R_atom': [(1, 5), (5, 0), (7, 2), (2, 8)]})
328+
240329
@classmethod
241330
def tearDownClass(cls):
242331
"""

0 commit comments

Comments
 (0)