def setUp(self): os.environ["PATH"] = os.path.expandvars( "$AUTOTST/test/bin:") + os.environ["PATH"] self.reaction = Reaction("CC+[O]O_[CH2]C+OO") self.calculator = Gaussian( directory=os.path.expandvars("$AUTOTST/test")) self.job = Job(reaction=self.reaction, calculator=self.calculator, partition="test")
def setUp(self): os.environ["PATH"] = os.path.expandvars( "$AUTOTST/test/bin:") + os.environ["PATH"] os.environ["TEST_STATUS"] = "None" self.reaction = Reaction("CC+[O]O_[CH2]C+OO") self.calculator = Gaussian( directory=os.path.expandvars("$AUTOTST/test")) self.job = Job(reaction=self.reaction, calculator=self.calculator, partition="test", username="******", exclude="test", account="test") self.job2 = Job(reaction=self.reaction, calculator=self.calculator, partition="test", username="******", exclude="test", account=["test"])
def get_rotor_info(self, conformer, torsion): """ Formats and returns info about torsion as it should appear in an Arkane species.py The following are needed for an Arkane input file: - scanLog :: Gaussian output log of freq calculation on optimized geometry - pivots :: torsion center: j,k of i,j,k,l (Note Arkane begins indexing with 1) - top :: ID of all atoms in one top (Note Arkane begins indexing with 1) Parameters: - conformer (Conformer): autotst conformer object - torsion (Torsion): autotst torsion object Returns: - info (str): a string containing all of the relevant information for a hindered rotor scan """ #torsion = conformer.torsions[torsion_index] _, j, k, _ = torsion.atom_indices # Adjusted since mol's IDs start from 0 while Arkane's start from 1 tor_center_adj = [j+1, k+1] if isinstance(conformer, TS): tor_log = os.path.join( self.directory, "ts", conformer.reaction_label, "rotors", comformer.reaction_label + f"_36by10_{j}_{k}.log" ) label = comformer.reaction_label + f"_36by10_{j}_{k}" elif isinstance(conformer, Conformer): tor_log = os.path.join( self.directory, "species", conformer.smiles, "rotors", conformer.smiles + f'_36by10_{j}_{k}.log' ) label = conformer.smiles + f'_36by10_{j}_{k}' if not os.path.exists(tor_log): logging.info( f"Torsion log file does not exist for {torsion}") return "" try: validated = all(Job(directory=self.directory).verify_rotor(conformer=conformer, label=label)) except AttributeError: validated = False if not validated: logging.error(f'Rotor {label} could not be verified, using RRHO approximation instead.') return '' top_IDs = [] for num, tf in enumerate(torsion.mask): if tf: top_IDs.append(num) # Adjusted to start from 1 instead of 0 top_IDs_adj = [ID+1 for ID in top_IDs] info = f" HinderedRotor(scanLog=Log('{tor_log}'), pivots={tor_center_adj}, top={top_IDs_adj}, fit='fourier')," return info
class JobTest(unittest.TestCase): def setUp(self): self.reaction = Reaction("CC+[O]O_[CH2]C+OO") self.calculator = Gaussian( directory=os.path.expandvars("$AUTOTST/test")) self.job = Job(reaction=self.reaction, calculator=self.calculator, partition="test") os.environ["PATH"] = os.path.expandvars( "$AUTOTST/test/bin:") + os.environ["PATH"] def test_read_log(self): path = os.path.expandvars("$AUTOTST/test/bin/log-files/CC_0.log") atoms = self.job.read_log(path) self.assertEqual(len(atoms), 8) carbon_count = 0 hydrogen_count = 0 for atom in atoms: if atom.symbol == "H": hydrogen_count += 1 elif atom.symbol == "C": carbon_count += 1 self.assertEqual(hydrogen_count, 6) self.assertEqual(carbon_count, 2) def test_write_input(self): self.assert_(True) def test_check_complete(self): ### I don't know how to create alaises in a python script self.assertFalse(self.job.check_complete("test1")) self.assertTrue(self.job.check_complete("test2")) ### For conformers def test_submit_conformer(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/species")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/species")) self.reaction.generate_reactants_and_products() conformer = self.reaction.reactants[0].conformers.values()[0][0] label = self.job.submit_conformer(conformer) self.assertEquals(label, "{}_{}".format(conformer.smiles, conformer.index)) def test_calculate_conformer(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/species")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/species")) conformer = Conformer(smiles='CC', index=0) result = self.job.calculate_conformer(conformer=conformer) self.assertTrue(result) conformer = Conformer(smiles='CC(Cl)(Cl)Cl', index=0) result = self.job.calculate_conformer(conformer=conformer) self.assertFalse(result) def test_calculate_species(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/species")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/species")) self.reaction.generate_reactants_and_products() for species in self.reaction.reactants + self.reaction.products: self.job.calculate_species(species) for smiles in species.conformers.keys(): self.assertTrue( os.path.exists( os.path.join( os.path.expandvars("$AUTOTST/test/species/"), smiles, smiles + ".log"))) def test_submit_transitionstate(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/ts")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/ts")) ts = self.reaction.ts["forward"][0] ts.get_molecules() for opt_type in ["shell", "center", "overall"]: label = self.job.submit_transitionstate(ts, opt_type=opt_type) if opt_type == "overall": self.assertEqual( label, "{}_{}_{}".format(ts.reaction_label, ts.direction, ts.index)) else: self.assertEqual( label, "{}_{}_{}_{}".format(ts.reaction_label, ts.direction, opt_type, ts.index)) def test_calculate_transitionstate(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/ts")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/ts")) ts = self.reaction.ts["forward"][0] ts.get_molecules() result = self.job.calculate_transitionstate(ts) self.assertTrue(result) def test_calculate_reaction(self): del self.reaction.ts["reverse"] result = self.job.calculate_reaction() self.assertTrue(result) def tearDown(self): if os.path.exists(os.path.expandvars("$AUTOTST/test/species")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/species")) if os.path.exists(os.path.expandvars("$AUTOTST/test/ts")): shutil.rmtree(os.path.expandvars("$AUTOTST/test/ts"))
def test_setup2(self): job = Job(directory=".") self.assertEqual(job.directory, ".") self.assertEqual(job.scratch, ".")
class JobTest(unittest.TestCase): def setUp(self): os.environ["PATH"] = os.path.expandvars( "$AUTOTST/test/bin:") + os.environ["PATH"] os.environ["TEST_STATUS"] = "None" self.reaction = Reaction("CC+[O]O_[CH2]C+OO") self.calculator = Gaussian( directory=os.path.expandvars("$AUTOTST/test")) self.job = Job(reaction=self.reaction, calculator=self.calculator, partition="test", username="******", exclude="test", account="test") self.job2 = Job(reaction=self.reaction, calculator=self.calculator, partition="test", username="******", exclude="test", account=["test"]) def test_setup(self): self.assertEqual(self.job.username, "test") self.assertEqual(self.job.exclude, "test") self.assertEqual(self.job.partition, "test") self.assertEqual(self.job.account, "test") self.assertEqual(self.job.label, self.reaction.label) def test_setup2(self): job = Job(directory=".") self.assertEqual(job.directory, ".") self.assertEqual(job.scratch, ".") def test_read_log(self): path = os.path.expandvars("$AUTOTST/test/bin/log-files/CC_0.log") atoms = self.job.read_log(path) self.assertEqual(len(atoms), 8) carbon_count = 0 hydrogen_count = 0 for atom in atoms: if atom.symbol == "H": hydrogen_count += 1 elif atom.symbol == "C": carbon_count += 1 self.assertEqual(hydrogen_count, 6) self.assertEqual(carbon_count, 2) def test_write_input(self): self.assertTrue(True) def test_check_complete(self): ### I don't know how to create alaises in a python script os.environ["TEST_STATUS"] = "None" self.assertFalse(self.job.check_complete("test1")) self.assertTrue(self.job.check_complete("test2")) def test_submit(self): result = self.job.submit("echo testing") self.assertTrue(result) ### For conformers def test_submit_conformer(self): self.reaction.generate_reactants_and_products() conformer = list(self.reaction.reactants[0].conformers.values())[0][0] label = self.job.submit_conformer(conformer) self.assertEqual(label, f"{conformer.smiles}_{conformer.index}") def test_submit_conformer2(self): self.reaction.generate_reactants_and_products() conformer = list(self.reaction.reactants[0].conformers.values())[0][0] label = self.job2.submit_conformer(conformer) self.assertEqual(label, f"{conformer.smiles}_{conformer.index}") def test_calculate_conformer(self): conformer = Conformer(smiles='CC', index=0) result = self.job.calculate_conformer(conformer=conformer) self.assertTrue(result) def test_calculate_species(self): self.reaction.generate_reactants_and_products() for species in self.reaction.reactants + self.reaction.products: self.job.calculate_species(species) for smiles in species.conformers.keys(): self.assertTrue( os.path.exists( os.path.join( os.path.expandvars("$AUTOTST/test/species/"), smiles, smiles + ".log"))) def test_submit_transitionstate(self): ts = self.reaction.ts["forward"][0] ts.get_molecules() for opt_type in ["shell", "center", "overall"]: label = self.job.submit_transitionstate(ts, opt_type=opt_type) if opt_type == "overall": self.assertEqual( label, f"{ts.reaction_label}_{ts.direction}_{ts.index}") else: self.assertEqual( label, f"{ts.reaction_label}_{ts.direction}_{opt_type}_{ts.index}" ) def test_submit_transitionstate2(self): ts = self.reaction.ts["forward"][0] ts.get_molecules() for opt_type in ["shell", "center", "overall"]: label = self.job2.submit_transitionstate(ts, opt_type=opt_type) if opt_type == "overall": self.assertEqual( label, f"{ts.reaction_label}_{ts.direction}_{ts.index}") else: self.assertEqual( label, f"{ts.reaction_label}_{ts.direction}_{opt_type}_{ts.index}" ) def test_calculate_transitionstate(self): ts = self.reaction.ts["forward"][0] ts.get_molecules() result = self.job.calculate_transitionstate(ts) self.assertTrue(result) def test_calculate_reaction(self): del self.reaction.ts["reverse"] result = self.job.calculate_reaction() self.assertTrue(result)