def test_in_database_with_actual_database(self): db_file = os.path.join(db_dir, "db.json") dir2620 = os.path.join(module_dir, "..", "..", "test_files", "2620_complete") mol2620 = QCOutput(os.path.join( dir2620, "mol.qout.opt_0")).data["initial_molecule"] parse_firetask = QChemToDb(calc_dir=dir2620, db_file=db_file) parse_firetask.run_task({}) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule( molecule=self.neg_tfsi, db_file=db_file, depth=0, additional_charges=[-2, 1], do_triplets=False, ) ft.run_task({}) self.assertEqual(ft.check_db, True) self.assertEqual(ft.charges, [-1, 0, -2, 1]) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 623) self.assertEqual(ft._in_database(mol2620), True) mol2620.set_charge_and_spin(charge=0) self.assertEqual(ft._in_database(mol2620), False)
def test_babel_PC_depth_0_vs_depth_10(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, depth=0, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db, False) depth0frags = ft.unique_fragments self.assertEqual(len(depth0frags), 295) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 295 * 3) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, depth=10, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db, False) depth10frags = ft.unique_fragments self.assertEqual(len(depth10frags), 63) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 63 * 3) for fragment10 in depth10frags: found = False for fragment0 in depth0frags: if fragment0.isomorphic_to(fragment10): found = True self.assertEqual(found, True)
def test_babel_PC_depth_0_vs_depth_10(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, depth=0, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) depth0frags = ft.unique_fragments self.assertEqual(len(depth0frags), 295) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 295*3) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, depth=10, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) depth10frags = ft.unique_fragments self.assertEqual(len(depth10frags), 63) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 63*3) for fragment10 in depth10frags: found = False for fragment0 in depth0frags: if fragment0.isomorphic_to(fragment10): found = True self.assertEqual(found, True)
def test_neg_TFSI_with_additional_charges(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule( molecule=self.neg_tfsi, depth=0, additional_charges=[-2, 1], do_triplets=False, ) ft.run_task({}) self.assertEqual(ft.check_db, False) self.assertEqual(ft.charges, [-1, 0, -2, 1]) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 624) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule( molecule=self.neg_tfsi, depth=0, additional_charges=[0, 1], do_triplets=False, ) ft.run_task({}) self.assertEqual(ft.check_db, False) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 468)
def test_babel_TFSI(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.tfsi, depth=0, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) self.assertEqual(ft.charges,[-1,0,1]) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 468)
def test_edges_given_PC(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, edges=self.pc_edges, depth=0, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) self.assertEqual(ft.charges,[-1,0,1]) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 295 * 3)
def test_babel_TFSI(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.tfsi, depth=0, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) self.assertEqual(ft.charges,[-1,0,1]) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 468)
def test_edges_given_PC(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.pc, edges=self.pc_edges, depth=0, open_rings=False, do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,False) self.assertEqual(ft.charges,[-1,0,1]) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 295 * 3)
def test_EC_neg(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.neg_ec, depth=1, check_db=False) ft.run_task({}) self.assertEqual(ft.check_db,False) frags = ft.unique_fragments self.assertEqual(len(frags), 7) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 15)
def test_EC_neg(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.neg_ec, depth=1, check_db=False) ft.run_task({}) self.assertEqual(ft.check_db,False) frags = ft.unique_fragments self.assertEqual(len(frags), 7) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 14)
def test_in_database_with_actual_database(self): db_file=os.path.join(db_dir, "db.json") dir2620=os.path.join(module_dir, "..", "..", "test_files", "2620_complete") mol2620=QCOutput(os.path.join(dir2620,"mol.qout.opt_0")).data["initial_molecule"] parse_firetask = QChemToDb(calc_dir=dir2620, db_file=db_file) parse_firetask.run_task({}) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.neg_tfsi, db_file=db_file, depth=0, additional_charges=[-2,1], do_triplets=False) ft.run_task({}) self.assertEqual(ft.check_db,True) self.assertEqual(ft.charges,[-1,0,-2,1]) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 623) self.assertEqual(ft._in_database(mol2620),True) mol2620.set_charge_and_spin(charge=0) self.assertEqual(ft._in_database(mol2620),False)
def test_in_database_and_EC_neg_frag(self): db_file = os.path.join(db_dir, "db.json") mmdb = QChemCalcDb.from_db_file(db_file, admin=True) with open(os.path.join(module_dir, "..", "..", "test_files","sb40.json")) as f: tmp = json.load(f) for entry in tmp: mmdb.insert(entry) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.neg_ec, depth=1, qchem_input_params={"pcm_dielectric": 40.0}, check_db=True, db_file=db_file) ft.run_task({}) self.assertEqual(ft.check_db,True) frags = ft.unique_fragments self.assertEqual(len(frags), 7) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 0) mmdb.reset()
def test_in_database_and_EC_neg_frag(self): db_file = os.path.join(db_dir, "db.json") mmdb = QChemCalcDb.from_db_file(db_file, admin=True) with open(os.path.join(module_dir, "..", "..", "test_files","sb40.json")) as f: tmp = json.load(f) for entry in tmp: mmdb.insert(entry) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: ft = FragmentMolecule(molecule=self.neg_ec, depth=1, qchem_input_params={"pcm_dielectric": 40.0}, check_db=True, db_file=db_file) ft.run_task({}) self.assertEqual(ft.check_db,True) frags = ft.unique_fragments self.assertEqual(len(frags), 7) self.assertEqual( len(FWAction_patch.call_args[1]["additions"]), 0) mmdb.reset()