def validate_transitionstate(self, transitionstate, vibrational_analysis=True): validated = False if vibrational_analysis: vib = VibrationalAnalysis(transitionstate=transitionstate, directory=self.directory) validated = vib.validate_ts() if not validated: logging.info( "Could not validate with Vibrational Analysis... Running an IRC to validate instead..." ) label = self.submit_transitionstate(transitionstate, opt_type="irc") while not self.check_complete(label): time.sleep(15) result = self.calculator.validate_irc(calc=irc_calc) if result: logging.info("Validated via IRC") return True else: logging.info( "Could not validate this conformer... trying the next lowest energy conformer" ) return False else: logging.info("Validated via Vibrational Analysis") return True
def validate_transitionstate(self, transitionstate, calculator, vibrational_analysis=True): validated = False if vibrational_analysis: vib = VibrationalAnalysis(ts=transitionstate, scratch=calculator.scratch) validated = vib.validate_ts() if not validated: logging.info("Running an IRC to validate") irc_calc = calculator.get_irc_calc(ts=transitionstate) label = self.submit_transitionstate(transitionstate, irc_calc, "general") while not self.check_complete(label): time.sleep(15) result = calculator.validate_irc(calc=irc_calc) if result: logging.info("Validated via IRC") return True else: logging.info( "Could not validate this conformer... trying the next lowest energy conformer" ) return False else: logging.info("Validated via Vibrational Analysis") return True
class VibrationalAnalysisTest(unittest.TestCase): def setUp(self): self.reaction = Reaction("CC+[O]O_[CH2]C+OO") self.reaction.get_labeled_reaction() self.ts = self.reaction.ts["forward"][0] self.ts.get_molecules() directory = os.path.expandvars("$AUTOTST/test") if not os.path.exists( os.path.join(directory, "ts", self.reaction.label, "conformers")): os.makedirs( os.path.join(directory, "ts", self.reaction.label, "conformers")) if not os.path.exists( os.path.join(directory, "ts", self.reaction.label, self.reaction.label + ".log")): shutil.copy( os.path.join(directory, "bin", "log-files", self.reaction.label + "_forward_0.log"), os.path.join(directory, "ts", self.reaction.label, "conformers", self.reaction.label + "_forward_0.log")) self.directory = directory self.vibrational_analysis = VibrationalAnalysis( transitionstate=self.ts, directory=self.directory) def tearDown(self): directory = os.path.expandvars("$AUTOTST/test") if os.path.exists(os.path.join(directory, "ts")): shutil.rmtree(os.path.join(directory, "ts")) for head, _, files in os.walk(os.path.expandvars("$AUTOTST")): for fi in files: if fi.endswith(".symm"): os.remove(os.path.join(head, fi)) def test_get_log_file(self): log_file = self.vibrational_analysis.get_log_file() actual_path = os.path.join( self.directory, "ts", self.ts.reaction_label, "conformers", "{}_{}_{}.log".format(self.ts.reaction_label, self.ts.direction, self.ts.index)) self.assertEqual(log_file, actual_path) def test_parse_vibrations(self): vibrations = self.vibrational_analysis.parse_vibrations() self.assertIsInstance(vibrations, list) self.assertEqual(len(vibrations), 27) def test_obtain_geometries(self): vibrations = self.vibrational_analysis.parse_vibrations() symbol_dict = { 17: "Cl", 9: "F", 8: "O", 7: "N", 6: "C", 1: "H", } atoms = [] parser = ccread(self.vibrational_analysis.log_file) for atom_num, coords in zip(parser.atomnos, parser.atomcoords[-1]): atoms.append(Atom(symbol=symbol_dict[atom_num], position=coords)) test_pre_geometry = Atoms(atoms) test_post_geometry = test_pre_geometry.copy() for vib, displacement in vibrations: if vib < 0: test_post_geometry.arrays["positions"] -= displacement pre_geometry, post_geometry = self.vibrational_analysis.obtain_geometries( ) for i, positions in enumerate(test_pre_geometry.arrays["positions"]): for j, x in enumerate(positions): self.assertEqual(x, pre_geometry.arrays["positions"][i][j]) for i, positions in enumerate(test_post_geometry.arrays["positions"]): for j, x in enumerate(positions): self.assertEqual(x, post_geometry.arrays["positions"][i][j]) def test_validate_ts(self): self.assertTrue(self.vibrational_analysis.validate_ts())