def test_generate_optimise_in(tmpdir, biphenyl): """ Test generating an optimize in file which captures the correct forcebalance run time settings. """ with tmpdir.as_cwd(): # parametrise the molecule OpenFF().run(biphenyl) # set some non-default values fb = ForceBalanceFitting(penalty_type="L2", max_iterations=100, minimum_trust_radius=10) tp = TorsionProfile(restrain_k=100) fb.add_target(target=tp) # now run the setup target_folders = tp.prep_for_fitting(molecule=biphenyl) fb.generate_optimise_in(target_data={tp.target_name: target_folders}) # read the file back in with open("optimize.in") as opt_in: opt_data = opt_in.read() assert "penalty_type L2" in opt_data assert "maxstep 100" in opt_data assert "mintrust 10" in opt_data assert "restrain_k 100" in opt_data assert "type TorsionProfile_OpenMM" in opt_data
def test_target_prep_no_data(tmpdir, biphenyl): """ Make sure an error is raised if we try and prep the target with misssing data. """ with tmpdir.as_cwd(): torsion_target = TorsionProfile() biphenyl.qm_scans = [] with pytest.raises(MissingReferenceData): torsion_target.prep_for_fitting(molecule=biphenyl)
def test_forcebalance_add_target(): """ Make sure the forcebalance optimiser can add targets when needed. """ fb = ForceBalanceFitting() fb.targets = {} torsion_target = TorsionProfile() fb.add_target(target=torsion_target) assert torsion_target.target_name in fb.targets
def test_torsion_metadata(tmpdir, biphenyl): """ Make sure that the metadata.json has the correct torsion index and torsion grid values. """ with tmpdir.as_cwd(): torsion_target = TorsionProfile() torsion_target.make_metadata(torsiondrive_data=biphenyl.qm_scans[0]) with open("metadata.json") as data: metadata = json.load(data) assert metadata["dihedrals"] == [ [6, 10, 11, 8], ] assert metadata["grid_spacing"] == [ 15, ] assert metadata["dihedral_ranges"] == [ [-165, 180], ]
def test_torsion_target_generation(tmpdir, biphenyl): """ Make sure that we can make a target from a molecule with its torsion scan data. """ with tmpdir.as_cwd(): torsion_target = TorsionProfile() target_folders = torsion_target.prep_for_fitting(molecule=biphenyl) # the name we expect for the target folder target_name = "TorsionProfile_OpenMM_10_11" # now make sure the folders have been made assert len(target_folders) == 1 assert target_folders[0] == target_name assert target_name in os.listdir() # now we need to check the forcebalance target files have been made required_files = [ "molecule.pdb", "metadata.json", "qdata.txt", "scan.xyz" ] for f in required_files: assert f in os.listdir(target_name)
def test_target_generation_ub_terms(tmpdir, biphenyl): """ Make sure we can make a valid target folder when we have ub terms. """ with tmpdir.as_cwd(): mol = biphenyl.copy(deep=True) # add a ub term for each angle for angle in mol.angles: mol.BondForce.create_parameter(atoms=(angle[0], angle[2]), length=1, k=1) torsion_target = TorsionProfile() target_folders = torsion_target.prep_for_fitting(molecule=mol) with pytest.raises( AtomValenceException, match= "Explicit valence for atom # 6 C, 5, is greater than permitted", ): _ = Ligand.from_file( os.path.join(target_folders[0], "molecule.pdb"))