Skip to content

Commit b8ddca5

Browse files
committed
Refactor Gaussian class to use pop method for parameter removal and update test setup to utilize utility functions for directory paths
1 parent 36144db commit b8ddca5

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

autotst/calculator/gaussian.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def get_rotor_calc(self,
179179
addsec=[addsec[:-1]])
180180

181181
ase_gaussian.atoms = self.conformer.ase_molecule
182-
del ase_gaussian.parameters['force']
182+
ase_gaussian.parameters.pop("force", None)
183183
return ase_gaussian
184184

185185
def get_conformer_calc(self):
@@ -232,7 +232,7 @@ def get_conformer_calc(self):
232232
extra=f"opt=(calcfc,maxcycles=900,{self.convergence}) freq IOP(7/33=1,2/16=3) scf=(maxcycle=900)",
233233
multiplicity=self.conformer.rmg_molecule.multiplicity)
234234
ase_gaussian.atoms = self.conformer.ase_molecule
235-
del ase_gaussian.parameters['force']
235+
ase_gaussian.parameters.pop("force", None)
236236
return ase_gaussian
237237

238238
def get_shell_calc(self):
@@ -293,7 +293,7 @@ def get_shell_calc(self):
293293
addsec=[combos]
294294
)
295295
ase_gaussian.atoms = self.conformer.ase_molecule
296-
del ase_gaussian.parameters['force']
296+
ase_gaussian.parameters.pop("force", None)
297297

298298
return ase_gaussian
299299

@@ -353,7 +353,7 @@ def get_center_calc(self):
353353
addsec=[addsec[:-1]]
354354
)
355355
ase_gaussian.atoms = self.conformer.ase_molecule
356-
del ase_gaussian.parameters['force']
356+
ase_gaussian.parameters.pop("force", None)
357357

358358
return ase_gaussian
359359

@@ -399,7 +399,7 @@ def get_overall_calc(self):
399399
extra="opt=(ts,calcfc,noeigentest,maxcycles=900) freq scf=(maxcycle=900) IOP(7/33=1,2/16=3)",
400400
multiplicity=self.conformer.rmg_molecule.multiplicity)
401401
ase_gaussian.atoms = self.conformer.ase_molecule
402-
del ase_gaussian.parameters['force']
402+
ase_gaussian.parameters.pop("force", None)
403403

404404
return ase_gaussian
405405

@@ -444,7 +444,7 @@ def get_irc_calc(self):
444444
multiplicity=self.conformer.rmg_molecule.multiplicity
445445
)
446446
ase_gaussian.atoms = self.conformer.ase_molecule
447-
del ase_gaussian.parameters['force']
447+
ase_gaussian.parameters.pop("force", None)
448448

449449
return ase_gaussian
450450

autotst/calculator/gaussian_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from ..species import Species, Conformer
3939
from ..geometry import Torsion
4040
from .gaussian import Gaussian
41+
from ..utils.paths import project_root, test_bin_dir
4142

4243
import ase
4344
import ase.calculators.gaussian
@@ -48,7 +49,7 @@
4849

4950
class TestGaussian(unittest.TestCase):
5051
def setUp(self):
51-
os.environ["PATH"] = os.path.expandvars("$AUTOTST/test/bin:") + os.environ["PATH"]
52+
os.environ["PATH"] = f"{test_bin_dir()}:{os.environ['PATH']}"
5253
rxn = Reaction(label='C+[O]O_[CH3]+OO')
5354
ts = rxn.ts["forward"][0]
5455
ts.get_molecules()
@@ -105,12 +106,14 @@ def test_irc_calc(self):
105106
self.assertIsInstance(calc_dict,dict)
106107

107108
def tearDown(self):
108-
if os.path.exists(os.path.expandvars("$AUTOTST/autotst/calculator/ts")):
109-
shutil.rmtree(os.path.expandvars("$AUTOTST/autotst/calculator/ts"))
110-
if os.path.exists(os.path.expandvars("$AUTOTST/autotst/calculator/species")):
111-
shutil.rmtree(os.path.expandvars("$AUTOTST/autotst/calculator/species"))
109+
ts_dir = project_root() / "autotst" / "calculator" / "ts"
110+
species_dir = project_root() / "autotst" / "calculator" / "species"
111+
if os.path.exists(ts_dir):
112+
shutil.rmtree(ts_dir)
113+
if os.path.exists(species_dir):
114+
shutil.rmtree(species_dir)
112115

113116
if __name__ == "__main__":
114117
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
115118

116-
119+

test/bin/g16

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/usr/bin/env python
22

33
import os, sys, shutil, time
4+
from pathlib import Path
45

56
input_file = sys.argv[1].split("/")[-1] + ".log"
67
directory_path = sys.argv[1].strip(input_file)
78
log_file = input_file.replace(".com", ".log")
8-
log_path = os.path.expandvars("$AUTOTST/test/bin/log-files")
9+
project_root = Path(__file__).resolve().parents[2]
10+
log_path = project_root / "test" / "bin" / "log-files"
911

1012
if os.path.join(log_path, log_file):
1113
shutil.copy(
1214
os.path.join(log_path, log_file),
1315
os.path.join(directory_path, log_file)
1416
)
1517

16-

0 commit comments

Comments
 (0)