def mod_sem(molecule): """Modified Seminario for bonds and angles.""" mod_sem = ModSeminario(molecule) mod_sem.modified_seminario_method() append_to_log('Mod_Seminario method complete') return molecule
def test_mod_sem_special_case(self): """Using xB97XD/6-311++G(d,p), scalling 0.957 on benzonitrile""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.mod_sem = ModSeminario(self.benzonitrile_hessian) # Compare the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual(self.benzonitrile_hessian.HarmonicBondForce, self.benzonitrile_mod_sem.HarmonicBondForce) self.assertEqual(self.benzonitrile_hessian.HarmonicAngleForce, self.benzonitrile_mod_sem.HarmonicAngleForce)
def test_mod_sem(self): """Using wB97XD/6-311++G(d,p), scalling 0.957""" # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.mod_sem = ModSeminario(self.benzene_hessian) # Get the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual(self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem.HarmonicBondForce) self.assertEqual(self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem.HarmonicAngleForce)
def mod_sem(molecule): """Modified Seminario for bonds and angles.""" append_to_log('Starting mod_Seminario method') mod_sem = ModSeminario(molecule) mod_sem.modified_seminario_method() append_to_log('Finishing Mod_Seminario method') return molecule
def test_mod_sem_special_case(self): """Using xB97XD/6-311++G(d,p), scaling 0.957, ensure mod_sem params are calculated properly.""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzonitrile_hessian.vib_scaling = 0.957 self.mod_sem = ModSeminario(self.benzonitrile_hessian) self.mod_sem.modified_seminario_method() self.assertEqual(self.benzonitrile_hessian.HarmonicBondForce, self.benzonitrile_mod_sem.HarmonicBondForce) self.assertEqual(self.benzonitrile_hessian.HarmonicAngleForce, self.benzonitrile_mod_sem.HarmonicAngleForce)
def test_mod_sem_scaling(self): """Using wB97XD/6-311++G(d,p), scaling 1, ensure mod_sem params are calculated properly.""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzene_hessian.vib_scaling = 1 self.mod_sem = ModSeminario(self.benzene_hessian) self.mod_sem.modified_seminario_method() self.assertEqual( self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem_vib_1.HarmonicBondForce, ) self.assertEqual( self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem_vib_1.HarmonicAngleForce, )
def test_mod_sem_no_symmetry(tmpdir): """ A simple regression test for the modified seminario method. # TODO expand these tests """ with tmpdir.as_cwd(): # the sdf file is at the qm geometry mol = Ligand.from_file(file_name=get_data("ethane.sdf")) hessian = np.loadtxt(fname=get_data("ethane_hessian.txt")) mol.hessian = hessian mod_sem = ModSeminario(molecule=mol) mod_sem.modified_seminario_method() # now check the values assert mol.HarmonicBondForce[( 0, 1)][0] == pytest.approx(0.15344171531887932) assert mol.HarmonicBondForce[( 0, 1)][1] == pytest.approx(192462.76956156612) assert mol.HarmonicBondForce[( 0, 2)][0] == pytest.approx(0.10954907576059233) assert mol.HarmonicBondForce[( 0, 2)][1] == pytest.approx(295645.6124892813) assert mol.HarmonicAngleForce[( 1, 0, 2)][0] == pytest.approx(1.9423960113296368) assert mol.HarmonicAngleForce[( 1, 0, 2)][1] == pytest.approx(374.76469990519263) assert mol.HarmonicAngleForce[( 1, 0, 3)][0] == pytest.approx(1.9422108316309619) assert mol.HarmonicAngleForce[( 1, 0, 3)][1] == pytest.approx(401.56353614024914) assert mol.HarmonicAngleForce[( 1, 0, 4)][0] == pytest.approx(1.9416241741805782) assert mol.HarmonicAngleForce[( 1, 0, 4)][1] == pytest.approx(371.0717571027322) assert mol.HarmonicAngleForce[( 2, 0, 3)][0] == pytest.approx(1.8787818480998344) assert mol.HarmonicAngleForce[( 2, 0, 3)][1] == pytest.approx(314.5677633711689) assert mol.HarmonicAngleForce[( 0, 1, 6)][0] == pytest.approx(1.9423960113296368) assert mol.HarmonicAngleForce[( 0, 1, 6)][1] == pytest.approx(399.59297576081184)
def mod_sem(molecule): """Modified Seminario for bonds and angles.""" append_to_log('Starting mod_Seminario method') ModSeminario(molecule).modified_seminario_method() molecule.symmetrise_bonded_parameters() append_to_log('Finishing Mod_Seminario method') return molecule
class TestSeminario(unittest.TestCase): def setUp(self): """ Set up the seminario test case by loading a pickled ligand that contains the hessian already :return: None """ self.home = os.getcwd() self.test_folder = os.path.join(os.path.dirname(__file__), 'files') # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) copy(os.path.join(self.test_folder, '.QUBEKit_states'), '.QUBEKit_states') self.molecules = unpickle() self.benzene_hessian, self.benzene_mod_sem = self.molecules['hessian'], self.molecules['mod_sem'] self.benzene_mod_sem_vib_1 = self.molecules['mod_sem_vib_1'] self.benzonitrile_hessian, self.benzonitrile_mod_sem = self.molecules['benzonitrile_hessian'], self.molecules['benzonitrile_mod_sem'] def test_mod_sem(self): """Using wB97XD/6-311++G(d,p), scalling 0.957""" # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.mod_sem = ModSeminario(self.benzene_hessian) # Get the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual(self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem.HarmonicBondForce) self.assertEqual(self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem.HarmonicAngleForce) def test_mod_sem_scalling(self): """Using wB97XD/6-311++G(d,p), scalling 1""" # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzene_hessian.vib_scaling = 1 self.mod_sem = ModSeminario(self.benzene_hessian) # Compare the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual(self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem_vib_1.HarmonicBondForce) self.assertEqual(self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem_vib_1.HarmonicAngleForce) def test_mod_sem_special_case(self): """Using xB97XD/6-311++G(d,p), scalling 0.957 on benzonitrile""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.mod_sem = ModSeminario(self.benzonitrile_hessian) # Compare the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual(self.benzonitrile_hessian.HarmonicBondForce, self.benzonitrile_mod_sem.HarmonicBondForce) self.assertEqual(self.benzonitrile_hessian.HarmonicAngleForce, self.benzonitrile_mod_sem.HarmonicAngleForce) def tearDown(self): """Remove the temp folder""" os.chdir(self.home)
def test_mod_sem_symmetry(tmpdir): """ A simple regression test for modified seminario method with symmetry. """ with tmpdir.as_cwd(): # the sdf file is at the qm geometry mol = Ligand.from_file(file_name=get_data("ethane.sdf")) hessian = np.loadtxt(fname=get_data("ethane_hessian.txt")) mol.hessian = hessian mod_sem = ModSeminario(molecule=mol) mod_sem.modified_seminario_method() mod_sem.symmetrise_bonded_parameters() # make sure symmetry groups are the same for bonds in mol.bond_types.values(): values = set() for bond in bonds: values.add(tuple(mol.HarmonicBondForce[bond])) assert len(values) == 1 for angles in mol.angle_types.values(): values = set() for angle in angles: values.add(tuple(mol.HarmonicAngleForce[angle])) assert len(values) == 1
class TestSeminario(unittest.TestCase): def setUp(self): """Set up the Seminario test by loading a pickled ligand that already contains the hessian.""" self.home = os.getcwd() self.test_folder = os.path.join(os.path.dirname(__file__), "files") # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) copy(os.path.join(self.test_folder, ".QUBEKit_states"), ".QUBEKit_states") self.molecules = unpickle() self.benzene_hessian, self.benzene_mod_sem = ( self.molecules["hessian"], self.molecules["mod_sem"], ) self.benzene_hessian.testing = True self.benzene_mod_sem_vib_1 = self.molecules["mod_sem_vib_1"] self.benzene_mod_sem_vib_1.testing = True self.benzonitrile_hessian = self.molecules["benzonitrile_hessian"] self.benzonitrile_hessian.testing = True self.benzonitrile_mod_sem = self.molecules["benzonitrile_mod_sem"] self.benzonitrile_mod_sem.testing = True def test_mod_sem(self): """Using wB97XD/6-311++G(d,p), scaling 0.957, ensure mod_sem params are calculated properly.""" # Make temp folder and move the pickle file in with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzene_hessian.vib_scaling = 0.957 self.mod_sem = ModSeminario(self.benzene_hessian) # Get the seminario predicted values self.mod_sem.modified_seminario_method() self.assertEqual( self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem.HarmonicBondForce, ) self.assertEqual( self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem.HarmonicAngleForce, ) def test_mod_sem_scaling(self): """Using wB97XD/6-311++G(d,p), scaling 1, ensure mod_sem params are calculated properly.""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzene_hessian.vib_scaling = 1 self.mod_sem = ModSeminario(self.benzene_hessian) self.mod_sem.modified_seminario_method() self.assertEqual( self.benzene_hessian.HarmonicBondForce, self.benzene_mod_sem_vib_1.HarmonicBondForce, ) self.assertEqual( self.benzene_hessian.HarmonicAngleForce, self.benzene_mod_sem_vib_1.HarmonicAngleForce, ) def test_mod_sem_special_case(self): """Using xB97XD/6-311++G(d,p), scaling 0.957, ensure mod_sem params are calculated properly.""" with tempfile.TemporaryDirectory() as temp: os.chdir(temp) self.benzonitrile_hessian.vib_scaling = 0.957 self.mod_sem = ModSeminario(self.benzonitrile_hessian) self.mod_sem.modified_seminario_method() self.assertEqual( self.benzonitrile_hessian.HarmonicBondForce, self.benzonitrile_mod_sem.HarmonicBondForce, ) self.assertEqual( self.benzonitrile_hessian.HarmonicAngleForce, self.benzonitrile_mod_sem.HarmonicAngleForce, ) def tearDown(self): """Remove the temp working directory.""" os.chdir(self.home)
# Reshape hessian conversion = constants.HA_TO_KCAL_P_MOL / (constants.BOHR_TO_ANGS ** 2) hessian = np.array(hessian).reshape(int(len(hessian) ** 0.5), -1) * conversion # Extract optimised structure opt_struct = client.query_procedures(id=opt_record)[0].get_final_molecule() # Initialise Ligand object using the json dict from qcengine mol = Ligand(opt_struct.json_dict(), name='initial_test') # Set the qm coords to the input coords from qcengine mol.coords['qm'] = mol.coords['input'] # Insert hessian and optimised coordinates mol.hessian = hessian mol.parameter_engine = 'none' # Create empty parameter dicts Parametrisation(mol).gather_parameters() print(item) with open('Modified_Seminario_Bonds.txt', 'a+') as bonds_file, \ open('Modified_Seminario_Angles.txt', 'a+') as angles_file: bonds_file.write(f'\n\n{smiles}\n\n') angles_file.write(f'\n\n{smiles}\n\n') # Get Mod Sem angle and bond params ModSeminario(mol).modified_seminario_method()