コード例 #1
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_check_torsion_drive_scan_range():
    """
    Make sure the scan range is always order lowest to largest.
    """
    td = TorsionDriveData(dihedral=(6, 10, 11, 8),
                          torsion_drive_range=(10, -90))
    assert td.torsion_drive_range == (-90, 10)
コード例 #2
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_from_qdata():
    """
    Make sure we can create a valid TorsionDriveData from qdata.
    """
    td = TorsionDriveData.from_qdata(dihedral=(6, 10, 11, 8),
                                     qdata_file=get_data("biphenyl_qdata.txt"))
    # validate all angles
    td.validate_angles()
コード例 #3
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_max_min_angle():
    """
    Make sure the max and min angle are updated.
    """
    td = TorsionDriveData(dihedral=(6, 10, 11, 8),
                          torsion_drive_range=(-40, 40))
    assert td.max_angle == 40
    assert td.min_angle == -40
コード例 #4
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_missing_reference_data():
    """
    Make sure that missing reference data is identified in a TorsionDriveData object.
    """
    td = TorsionDriveData.from_qdata(dihedral=(6, 10, 11, 8),
                                     qdata_file=get_data("biphenyl_qdata.txt"))
    del td.reference_data[0]
    with pytest.raises(MissingReferenceData):
        td.validate_angles()
コード例 #5
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_inconsistent_scan_range():
    """
    Make sure an error is raised if we try and make a torsiondrivedata object which is inconsistent.
    """
    with pytest.raises(TorsionDriveDataError):
        _ = TorsionDriveData.from_qdata(
            dihedral=(6, 10, 11, 8),
            qdata_file=get_data("biphenyl_qdata.txt"),
            grid_spacing=10,
        )
コード例 #6
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_qdata_round_trip(tmpdir):
    """
    Try and round trip a qdata txt file to a TorsionDriveData object and back.
    """
    with tmpdir.as_cwd():
        mol = Ligand.from_file(file_name=get_data("biphenyl.sdf"))
        td_ref = TorsionDriveData.from_qdata(
            dihedral=(6, 10, 11, 8), qdata_file=get_data("biphenyl_qdata.txt"))
        # now write to file
        export_torsiondrive_data(molecule=mol, tdrive_data=td_ref)
        # now make a second object
        td_new = TorsionDriveData.from_qdata(dihedral=(6, 10, 11, 8),
                                             qdata_file="qdata.txt")
        assert td_ref.dihedral == td_new.dihedral
        for angle, ref_result in td_ref.reference_data.items():
            new_result = td_new.reference_data[angle]
            assert ref_result.angle == new_result.angle
            assert ref_result.energy == pytest.approx(new_result.energy)
            assert np.allclose(ref_result.geometry.tolist(),
                               new_result.geometry.tolist())
コード例 #7
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def biphenyl():
    """
    Load up a biphenyl molecule with some torsiondrive data.
    """
    # load biphenyl
    mol = Ligand.from_file(file_name=get_data("biphenyl.sdf"))
    # load the torsiondrive data
    td_data = TorsionDriveData.from_qdata(
        qdata_file=get_data("biphenyl_qdata.txt"), dihedral=(6, 10, 11, 8))
    mol.add_qm_scan(scan_data=td_data)
    return mol
コード例 #8
0
    def _collect_results(self, td_state: Dict[str, Any],
                         molecule: "Ligand") -> "Ligand":
        """
        After the torsiondrive has been completed collect the results and pack them into the ligand.
        """
        # torsiondrive will only give us the lowest energy for each grid point
        # we have to then work out what the final geometry is from this
        optimised_energies = td_api.collect_lowest_energies(td_state=td_state)
        final_grid = td_state["grid_status"]
        # make a torsiondrive data store assuming 1D only
        torsion_data = TorsionDriveData(
            grid_spacing=self.grid_spacing,
            dihedral=td_state["dihedrals"][0],
            torsion_drive_range=td_state["dihedral_ranges"][0],
        )
        # now grab each grid point in sorted order
        for (
                angle,
                energy,
        ) in sorted(optimised_energies.items()):
            # grab all optimisation done at this angle
            optimisations = final_grid[str(angle[0])]
            # loop over each result and check if the energy matches the lowest
            # results -> (initial geometry, final geometry, final energy)
            for result in optimisations:
                if result[-1] == energy:
                    grid_data = TorsionData(
                        angle=angle[0],
                        geometry=np.array(result[1]) * constants.BOHR_TO_ANGS,
                        energy=energy,
                    )
                    torsion_data.add_grid_point(grid_data=grid_data)
                    break
        # validate the data
        torsion_data.validate_angles()
        # dump to file (qdata.txt and scan.xyz)
        export_torsiondrive_data(molecule=molecule, tdrive_data=torsion_data)
        # dump the qubekit torsion data to file
        torsion_data.to_file("scan_data.json")
        # save to mol
        molecule.add_qm_scan(scan_data=torsion_data)
        # dump the torsiondrive state to file
        self._dump_state(td_state=td_state)
        # now remove all temp folders
        for f in os.listdir("."):
            if os.path.isdir(f):
                shutil.rmtree(f, ignore_errors=True)

        return molecule
コード例 #9
0
ファイル: test_forcebalance.py プロジェクト: qubekit/QUBEKit
def test_central_bond():
    """
    Check the central bond property.
    """
    td = TorsionDriveData(dihedral=(6, 10, 11, 8))
    assert td.central_bond == (10, 11)