Skip to content

Commit 502b080

Browse files
authored
Allow ARC to use mockter as a TS guess adapter (#784)
will be used for functional tests of ARC and T3 Tests added
2 parents 112c267 + 870761a commit 502b080

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

arc/job/adapters/mockter.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def __init__(self,
122122
self.command = 'mockter'
123123
self.url = ''
124124

125-
if species is None:
126-
raise ValueError('Cannot execute Mockter without an ARCSpecies object.')
125+
if species is None and reactions is None:
126+
raise ValueError('Cannot execute Mockter without an ARCSpecies or an ARCReaction object.')
127127

128128
_initialize_adapter(obj=self,
129129
is_ts=False,
@@ -178,7 +178,7 @@ def write_input_file(self) -> None:
178178
input_dict['memory'] = self.input_file_memory
179179
input_dict['method'] = self.level.method
180180
input_dict['multiplicity'] = self.multiplicity
181-
input_dict['xyz'] = xyz_to_str(self.xyz)
181+
input_dict['xyz'] = xyz_to_str(self.get_mock_xyz())
182182
input_dict['job_type'] = self.job_type
183183
input_dict['memory'] = self.input_file_memory
184184

@@ -238,7 +238,23 @@ def set_input_file_memory(self) -> None:
238238
Set the input_file_memory attribute.
239239
"""
240240
self.input_file_memory = self.job_memory_gb
241-
241+
242+
def get_mock_xyz(self) -> Optional[dict]:
243+
"""
244+
Get the xyz coordinates for the mock job.
245+
"""
246+
if self.xyz is not None:
247+
return self.xyz
248+
if self.species is not None and len(self.species):
249+
return self.species[0].get_xyz()
250+
if self.reactions is not None and len(self.reactions):
251+
ts_xyz_str = ''
252+
reactants, _ = self.reactions[0].get_reactants_and_products()
253+
for r in reactants:
254+
ts_xyz_str += xyz_to_str(r.get_xyz()) + '\n'
255+
return str_to_xyz(ts_xyz_str)
256+
return None
257+
242258
def execute_incore(self):
243259
"""
244260
Execute a job incore.
@@ -250,7 +266,7 @@ def execute_incore(self):
250266
if self.species[0].is_ts:
251267
freqs[0] = -500
252268
output = {'adapter': 'mockter',
253-
'xyz': input['xyz'],
269+
'xyz': xyz,
254270
'sp': e_elect,
255271
'T1': 0.0002,
256272
'freqs': freqs,

arc/job/adapters/mockter_test.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from arc.common import ARC_PATH, read_yaml_file
1313
from arc.job.adapters.mockter import MockAdapter
1414
from arc.level import Level
15+
from arc.reaction.reaction import ARCReaction
1516
from arc.settings.settings import input_filenames, output_filenames
1617
from arc.species import ARCSpecies
1718

@@ -47,6 +48,16 @@ def setUpClass(cls):
4748
species=[ARCSpecies(label='spc3', xyz=['O 0 0 1\nH 0 0 0\nH 1 0 0'], is_ts=True)],
4849
testing=True,
4950
)
51+
cls.job_4 = MockAdapter(job_type='tsg',
52+
level=Level(method='mock)', basis='cc-pVmockZ'),
53+
project='test',
54+
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_MockAdapter_4'),
55+
reactions=[ARCReaction(r_species=[ARCSpecies(label='O', smiles='[O]'),
56+
ARCSpecies(label='CCC', smiles='CCC')],
57+
p_species=[ARCSpecies(label='OH', smiles='[OH]'),
58+
ARCSpecies(label='CCCyl', smiles='[CH2]CC')])],
59+
testing=True,
60+
)
5061

5162
def test_set_cpu_and_mem(self):
5263
"""Test assigning number of cpu's and memory"""
@@ -109,6 +120,31 @@ def test_write_input_file(self):
109120
'H 1.00000000 0.00000000 0.00000000'}
110121
self.assertEqual(content_3, job_3_expected_input_file)
111122

123+
def test_get_mock_xyz(self):
124+
"""Test getting the xyz coordinates from the mock input file"""
125+
self.job_1.write_input_file()
126+
xyz = self.job_1.get_mock_xyz()
127+
expected_xyz = ((0.0, 0.0, 1.0),)
128+
self.assertEqual(xyz['coords'], expected_xyz)
129+
130+
self.job_4.write_input_file()
131+
xyz = self.job_4.get_mock_xyz()
132+
expected_xyz = {'coords': ((0.0, 0.0, 0.0),
133+
(-1.23638885, -0.31576286, 0.08035856),
134+
(-0.01951084, 0.58603214, 0.20011967),
135+
(1.25111292, -0.12649245, -0.23138091),
136+
(-1.1299088, -1.20421894, 0.71100631),
137+
(-1.38117893, -0.64405306, -0.95389019),
138+
(-2.13745897, 0.21915243, 0.39632612),
139+
(-0.16491381, 1.47886657, -0.41803363),
140+
(0.08498971, 0.92174781, 1.23780143),
141+
(1.43621378, -1.00896698, 0.38941334),
142+
(1.1849428, -0.44879975, -1.27548267),
143+
(2.11210099, 0.5424951, -0.13623803)),
144+
'isotopes': (16, 12, 12, 12, 1, 1, 1, 1, 1, 1, 1, 1),
145+
'symbols': ('O', 'C', 'C', 'C', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H')}
146+
self.assertEqual(xyz, expected_xyz)
147+
112148
def test_executing_mockter(self):
113149
"""Test executing mockter"""
114150
self.job_1.execute()
@@ -118,7 +154,7 @@ def test_executing_mockter(self):
118154

119155
self.job_2.execute()
120156
output = read_yaml_file(os.path.join(self.job_2.local_path, output_filenames[self.job_2.job_adapter]))
121-
self.assertEqual(output['xyz'], 'O 0.00000000 0.00000000 1.00000000')
157+
self.assertEqual(output['xyz'], {'coords': ((0.0, 0.0, 1.0),), 'isotopes': (16,), 'symbols': ('O',)})
122158

123159
self.job_3.execute()
124160
output = read_yaml_file(os.path.join(self.job_3.local_path, output_filenames[self.job_3.job_adapter]))
@@ -131,7 +167,7 @@ def tearDownClass(cls):
131167
A function that is run ONCE after all unit tests in this class.
132168
Delete all project directories created during these unit tests
133169
"""
134-
for folder in ['test_MockAdapter_1', 'test_MockAdapter_2', 'test_MockAdapter_3']:
170+
for folder in ['test_MockAdapter_1', 'test_MockAdapter_2', 'test_MockAdapter_3', 'test_MockAdapter_4']:
135171
shutil.rmtree(os.path.join(ARC_PATH, 'arc', 'testing', folder), ignore_errors=True)
136172

137173

arc/scheduler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,8 @@ def spawn_ts_jobs(self):
16151615
if method in all_families_ts_adapters or \
16161616
(rxn.family is not None
16171617
and rxn.family in list(ts_adapters_by_rmg_family.keys())
1618-
and method in ts_adapters_by_rmg_family[rxn.family]):
1618+
and method in ts_adapters_by_rmg_family[rxn.family]) \
1619+
or 'mock' in method:
16191620
self.run_job(job_type='tsg',
16201621
job_adapter=method,
16211622
reactions=[rxn],

0 commit comments

Comments
 (0)