Example #1
0
 def test_combination_symmetries(self):
     # preparation
     pdb_0 = atomset.PDB()
     pdb_0.initialise("tests/data/symmetries/cluster_0.pdb", resname='AEN')
     pdb_1 = atomset.PDB()
     pdb_1.initialise("tests/data/symmetries/cluster_1.pdb", resname='AEN')
     pdb_2 = atomset.PDB()
     pdb_2.initialise("tests/data/symmetries/cluster_2.pdb", resname='AEN')
     symmetries3PTB = [{
         "3225:C3:AEN": "3227:C5:AEN",
         "3224:C2:AEN": "3228:C6:AEN"
     }, {
         "3230:N1:AEN": "3231:N2:AEN"
     }]
     RMSDCalc = RMSDCalculator.RMSDCalculator(symmetries3PTB)
     # funtion to test
     RMSD02 = RMSDCalc.computeRMSD(pdb_0, pdb_2)
     RMSD20 = RMSDCalc.computeRMSD(pdb_2, pdb_0)
     RMSD01 = RMSDCalc.computeRMSD(pdb_0, pdb_1)
     RMSD10 = RMSDCalc.computeRMSD(pdb_1, pdb_0)
     RMSD21 = RMSDCalc.computeRMSD(pdb_2, pdb_1)
     RMSD12 = RMSDCalc.computeRMSD(pdb_1, pdb_2)
     self.assertEqual(RMSD01, RMSD10)
     self.assertEqual(RMSD02, RMSD20)
     self.assertEqual(RMSD21, RMSD12)
Example #2
0
    def test_symmetryContactMapDifference(self):
        pdb_1 = atomset.PDB()
        pdb_1.initialise("tests/data/symmetries/cluster_1.pdb", resname='AEN')
        pdb_1_sym = atomset.PDB()
        pdb_1_sym.initialise("tests/data/symmetries/cluster_1_sym.pdb",
                             resname='AEN')
        symmetries3PTB = [{"3230:N1:AEN": "3231:N2:AEN"}]
        symmetryEvaluator = sym.SymmetryContactMapEvaluator(symmetries3PTB)
        symmetryEvaluatorEmpty = sym.SymmetryContactMapEvaluator()

        contactMap1, contacts1 = symmetryEvaluator.buildContactMap(
            pdb_1, 'AEN', 16)
        cluster = clustering.Cluster(pdb_1, contactMap=contactMap1)
        contactMap1Sym, contactsSym = symmetryEvaluator.createContactMap(
            pdb_1_sym, 'AEN', 16)
        contactMapNoSym, _ = symmetryEvaluator.createContactMap(
            pdb_1_sym, 'AEN', 16)

        goldenDifference = 0.0
        DifferenceSym = symmetryEvaluator.evaluateDifferenceDistance(
            contactMap1Sym, cluster.contactMap)
        DifferenceNosym = symmetryEvaluatorEmpty.evaluateDifferenceDistance(
            contactMapNoSym, cluster.contactMap)

        self.assertEqual(contacts1, contactsSym)
        self.assertAlmostEqual(goldenDifference, DifferenceSym)
        self.assertNotAlmostEqual(DifferenceSym, DifferenceNosym)
Example #3
0
def extractContactMapCoordinatesPDB(allCoordinates, params):
    trajCoords = []
    for coordinates in allCoordinates:
        if params.cm_mode == "p-lig":
            PDB = atomset.PDB()
            PDB.initialise(coordinates, resname=params.lig_resname)
            snapshotCoords = [
                coord for at in PDB.atomList
                for coord in PDB.atoms[at].getAtomCoords()
            ]
        else:
            snapshotCoords = []
        PDBCA = atomset.PDB()
        if params.extra_atoms:
            PDBCA.initialise(coordinates,
                             type=u"PROTEIN",
                             extra_atoms=EXTRA_ATOMS)
        else:
            PDBCA.initialise(coordinates, type=u"PROTEIN")
        snapshotCoords.extend([
            coord for at in PDBCA.atomList
            for coord in PDBCA.atoms[at].getAtomCoords()
        ])
        trajCoords.append(snapshotCoords)
    return trajCoords
Example #4
0
    def test_symmetryContactMapJaccard_XTC(self):
        xtc_obj = mdtraj.load("tests/data/symmetries/cluster_1.xtc",
                              top="tests/data/symmetries/cluster_1.pdb")
        topology = utilities.getTopologyFile(
            "tests/data/symmetries/cluster_1.pdb")
        pdb_1 = atomset.PDB()
        pdb_1.initialise(10 * xtc_obj.xyz[0], resname='AEN', topology=topology)
        topology = utilities.getTopologyFile(
            "tests/data/symmetries/cluster_1_sym.pdb")
        xtc_obj = mdtraj.load("tests/data/symmetries/cluster_1_sym.xtc",
                              top="tests/data/symmetries/cluster_1_sym.pdb")
        pdb_1_sym = atomset.PDB()
        pdb_1_sym.initialise(10 * xtc_obj.xyz[0],
                             resname='AEN',
                             topology=topology)
        symmetries3PTB = [{"3230:N1:AEN": "3231:N2:AEN"}]
        symmetryEvaluator = sym.SymmetryContactMapEvaluator(symmetries3PTB)
        symmetryEvaluatorEmpty = sym.SymmetryContactMapEvaluator()

        contactMap1, contacts1 = symmetryEvaluator.buildContactMap(
            pdb_1, 'AEN', 16)
        cluster = clustering.Cluster(pdb_1, contactMap=contactMap1)
        contactMap1Sym, contactsSym = symmetryEvaluator.createContactMap(
            pdb_1_sym, 'AEN', 16)
        contactMapNoSym, _ = symmetryEvaluator.createContactMap(
            pdb_1_sym, 'AEN', 16)

        goldenJaccard = 0.0
        Jaccard = symmetryEvaluator.evaluateJaccard(contactMap1Sym,
                                                    cluster.contactMap)
        JaccardNosym = symmetryEvaluatorEmpty.evaluateJaccard(
            contactMapNoSym, cluster.contactMap)
        self.assertEqual(contacts1, contactsSym)
        self.assertAlmostEqual(goldenJaccard, Jaccard)
        self.assertNotAlmostEqual(Jaccard, JaccardNosym)
Example #5
0
 def testPDB_sel_resnum_XTC(self):
     golden = "tests/data/ain_native_fixed.pdb"
     topology = utilities.getTopologyFile(golden)
     xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
     xtc = atomset.PDB()
     xtc.initialise(10 * xtc_obj.xyz[0], resnum=2, topology=topology)
     golden_pdb = atomset.PDB()
     golden_pdb.initialise(golden, resnum=2)
     self.assertEqual(xtc, golden_pdb)
Example #6
0
    def testPDB_RMSD(self):
        # preparation
        pdb_native = atomset.PDB()
        pdb_native.initialise("tests/data/ain_native_fixed.pdb", resname='AIN')
        pdb_traj = atomset.PDB()
        pdb_traj.initialise("tests/data/ain_trajectory.pdb", resname='AIN')
        RMSDCalc = RMSDCalculator.RMSDCalculator()

        # function to test
        RMSD = RMSDCalc.computeRMSD(pdb_native, pdb_traj)
        golden_RMSD = 3.928617
        self.assertAlmostEqual(RMSD, golden_RMSD, 5)
Example #7
0
def main(lig_resname, native_path, initial_path, up_lim, low_lim, filename):
    RMSDCalc = RMSDCalculator.RMSDCalculator()
    nativePDB = atomset.PDB()
    nativePDB.initialise(native_path, resname=lig_resname)
    filtered = []
    for conf in glob.glob(
            os.path.join(initial_path, "{}*.pdb".format(filename))):
        initialPDB = atomset.PDB()
        initialPDB.initialise(conf, resname=lig_resname)
        if low_lim < RMSDCalc.computeRMSD(nativePDB, initialPDB) < up_lim:
            filtered.append(conf)
    print(" ".join(filtered))
Example #8
0
def main(resname, files_glob, native):
    input_files = glob.glob(files_glob)
    nativePDB = atomset.PDB()
    nativePDB.initialise(native, resname=resname)
    RMSDCalc = RMSDCalculator.RMSDCalculator()
    results = {}
    for f in input_files:
        p = atomset.PDB()
        p.initialise(f, resname=resname)
        results[f] = RMSDCalc.computeRMSD(nativePDB, p)
    with open("rmsd_file.dat", "w") as fw:
        fw.write("File\tRMSD(A)\n")
        for f in results:
            fw.write("%s\t%.4f\n" % (f, results[f]))
Example #9
0
 def testPDB_RMSD_symmetries(self):
     # preparation
     pdb_native = atomset.PDB()
     pdb_native.initialise("tests/data/ain_native_fixed.pdb", resname='AIN')
     pdb_traj = atomset.PDB()
     pdb_traj.initialise("tests/data/ain_trajectory.pdb", resname='AIN')
     symDict = [{"1733:O1:AIN": "1735:O2:AIN"}]
     RMSDCalc = RMSDCalculator.RMSDCalculator(symDict)
     # function to test
     RMSD = RMSDCalc.computeRMSD(pdb_native, pdb_traj)
     reverseRMSD = RMSDCalc.computeRMSD(pdb_traj, pdb_native)
     golden_RMSD = 3.860743
     self.assertAlmostEqual(RMSD, reverseRMSD, 5)
     self.assertAlmostEqual(RMSD, golden_RMSD, 5)
Example #10
0
    def testPDB_contacts_XTC(self):
        # preparation
        golden = "tests/data/ain_native_fixed.pdb"
        topology = utilities.getTopologyFile(golden)
        xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
        xtc = atomset.PDB()
        xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
        golden_pdb = atomset.PDB()
        golden_pdb.initialise(golden, resname="AIN")

        # function to test
        contacts = golden_pdb.countContacts("AIN", 8)
        contacts_xtc = xtc.countContacts("AIN", 8)
        self.assertEqual(contacts, contacts_xtc)
Example #11
0
 def test_write_XTC_to_pdb(self):
     golden = "tests/data/ain_native_fixed.pdb"
     output = "xtc_to_pdb.pdb"
     topology = utilities.getTopologyFile(golden)
     xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
     xtc = atomset.PDB()
     xtc.initialise(xtc_obj.xyz[0], resname="AIN", topology=topology)
     top = utilities.getTopologyFile(golden)
     xtc.writePDB(output)
     golden_pdb = atomset.PDB()
     golden_pdb.initialise(golden, resname="AIN")
     output_pdb = atomset.PDB()
     output_pdb.initialise(output, resname="AIN")
     os.remove(output)
     self.assertEqual(golden_pdb.atoms, output_pdb.atoms)
Example #12
0
    def checkStartingConformations(self, goldenPath, outputPath):
        goldenPathInitial = os.path.join(goldenPath, "%d/initial_%d.pdb")
        outputPathInitial = os.path.join(outputPath, "initial_%d_%d.pdb")
        for j in range(3):
            for ij in range(1, 5):
                goldenInitial = atomset.PDB()
                goldenInitial.initialise(goldenPathInitial % (j, ij))

                outputInitial = atomset.PDB()
                if j == 0:
                    # initial structures will always be "initial_0_0.pdb"
                    outputInitial.initialise(outputPathInitial % (j, 0))
                else:
                    outputInitial.initialise(outputPathInitial % (j, ij % 4))
                self.assertEqual(goldenInitial, outputInitial)
Example #13
0
    def testPDB_COM_XTC(self):
        # preparation
        golden = "tests/data/ain_native_fixed.pdb"
        topology = utilities.getTopologyFile(golden)
        xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
        xtc = atomset.PDB()
        xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
        golden_pdb = atomset.PDB()
        golden_pdb.initialise(golden, resname="AIN")

        # assertion
        self.assertAlmostEqual(xtc.totalMass, golden_pdb.totalMass, 3)
        np.testing.assert_array_almost_equal(xtc.getCOM(),
                                             golden_pdb.getCOM(),
                                             decimal=3)
Example #14
0
    def testPDB_sel_type_hetero(self):
        # preparation
        pdb = atomset.PDB()

        # function to test
        pdb.initialise("tests/data/pdb_test_ligand.pdb", type="HETERO")

        # assertion
        pdbContent = "MODEL        1\n\
ATOM   1717  H   ASN A 119      25.915   9.925  -7.236  1.00 31.61           H  \n\
ATOM   1718  CA  ASN A 119      27.159  10.509  -6.736  1.00 33.83           C  \n\
TER\n\
HETATM 1733  O1  AIN L   1      13.907  16.130   0.624  0.50 28.52           O  \n\
TER\n\
HETATM 1753 CA    CA B   1      16.636  15.477   0.293  1.00  3.39          Ca2+\n\
TER\n\
ENDMDL\n\
END   \n"

        atom1 = atomset.Atom(
            "HETATM 1733  O1  AIN L   1      13.907  16.130   0.624  0.50 28.52           O  "
        )
        atom2 = atomset.Atom(
            "HETATM 1753 CA    CA B   1      16.636  15.477   0.293  1.00  3.39          Ca2+"
        )
        goldenAtomsDict = {atom1.id: atom1, atom2.id: atom2}

        self.assertEqual(pdb.pdb, pdbContent)
        self.assertEqual(pdb.atoms, goldenAtomsDict)
def checkSymmetryDict(clusteringBlock, initialStructures, resname, reschain,
                      resnum):
    """
        Check if the symmetries dictionary is valid for the ligand

        :param clusteringBlock: JSON block with the clustering-related parameters
        :type clusteringBlock: json
        :param initialStructures: List with initial structures
        :type initialStructures: list
        :param resname: Residue name of the ligand in the system pdb
        :type resname: str
        :param reschain: Chain name of the ligand in the system pdb
        :type reschain: str
        :param resnum: Residue number of the ligand in the system pdb
        :type resnum: int

        :raise AssertionError: If atoms are not found in the structure
     """
    symmetries = clusteringBlock[blockNames.ClusteringTypes.params].get(
        blockNames.ClusteringTypes.symmetries, {})
    for structure in initialStructures:
        PDB = atomset.PDB()
        PDB.initialise(structure,
                       resname=resname,
                       chain=reschain,
                       resnum=resnum)
        utilities.assertSymmetriesDict(symmetries, PDB)
Example #16
0
def main(outputDir, files, topology, structs, template=None):
    found = False
    if outputDir:
        utilities.makeFolder(outputDir)
    if topology is not None:
        topology_contents = utilities.getTopologyFile(topology)
    else:
        topology_contents = None
    if structs is not None:
        structs = set(structs)
    for f in files:
        name = os.path.split(f)[-1]
        templateName = os.path.join(outputDir,
                                    template) if template else os.path.join(
                                        outputDir, name[:-4] + "_%d.pdb")
        snapshots = utilities.getSnapshots(f, topology=topology)
        for i, snapshot in enumerate(snapshots):
            if structs is not None and i + 1 not in structs:
                continue
            if not isinstance(snapshot, basestring):
                PDB = atomset.PDB()
                PDB.initialise(snapshot, topology=topology_contents)
                snapshot = PDB.get_pdb_string(model_num=i + 1)
            if template:
                with open(templateName, 'w') as of:
                    of.write(snapshot)
                found = True
            else:
                with open(templateName % i, 'w') as of:
                    of.write(snapshot)
                found = True
    return found
Example #17
0
def getPDBCOM(allCoordinates, lig_resname):
    COMs = []
    for coordinates in allCoordinates:
        pdb = atomset.PDB()
        pdb.initialise(coordinates, resname=lig_resname, heavyAtoms=True)
        COMs.append(pdb.extractCOM())
    return COMs
def extractCOMMatrix(clusters, resname, topology=None):
    """ Extract a matrix contaning the coordinates of the center of mass of
    the ligand for each cluster structure

        clusters [In] List of clusters
        resname [In] Residue name of the ligand in the pdb
    """
    n = len(clusters)
    cluster_matrix = np.zeros((n, 3))
    metrics = np.zeros(n)
    population = np.zeros(n)
    total_elements = 0
    contacts = np.zeros(n)
    if clusters[0].pdb.isFromPDBFile() and topology is None:
        raise ValueError(
            "Need to pass a topology file to process non-pdb trajectories")
    for index, cluster in enumerate(clusters):
        metrics[index] = cluster.metrics[cluster.metricCol]
        contacts[index] = cluster.contacts
        ligandPDB = atomset.PDB()
        ligandPDB.initialise(cluster.pdb.get_pdb_string(),
                             resname=resname,
                             topology=topology)
        cluster_matrix[index, :] = ligandPDB.extractCOM()
        population[index] = cluster.elements
        total_elements += cluster.elements
    return cluster_matrix, metrics, total_elements, population, contacts
Example #19
0
def mapReference(ref, trajs, topology, topology_content):
    refPDB = atomset.PDB()
    refPDB.initialise(ref, type="PROTEIN", topology=topology_content)
    avgStruct = {
        atomID: refPDB.atoms[atomID].getAtomCoords()
        for atomID in refPDB.atoms
    }
    snapshotsTot = []
    for traj in trajs:
        snapshots = utilities.getSnapshots(traj, topology=topology)
        for snapshot in snapshots:
            PDB = atomset.PDB()
            PDB.initialise(snapshot, type="PROTEIN", topology=topology_content)
            snapshotsTot.append(PDB)

    return avgStruct, snapshotsTot
Example #20
0
def trajectory_and_snapshot_to_pdb(trajectory_path, snapshot, output_path,
                                   topology_contents):
    """
    Given an absolute path to a trajectory of Adaptive and a snapshot (MODEL) in xtc format, the function transform it
    into a PDB format.
    :param trajectory_path: Absolute path to a trajectory from Adaptive, in xtc format.
    :type trajectory_path:str
    :param snapshot: model of a trajectory that you want to transform.
    :type snapshot: int
    :param output_path: output path of the new pdb file.
    :type output_path: str
    :return: Creates a PDB file.
    """
    # get the path where the adaptive simulation resides
    topology_path_splited = trajectory_path.split(os.sep)
    epoch = int(topology_path_splited[-2])
    traj = adapt_tools.getTrajNum(topology_path_splited[-1])
    trajectory = adapt_tools.getSnapshots(trajectory_path)
    try:
        single_model = trajectory[snapshot]
        PDB = atomset.PDB()
        PDB.initialise(single_model,
                       topology=topology_contents.getTopology(epoch, traj))
    except IndexError:
        exit(
            "You are selecting the model {} for a trajectory that has {} models, please, reselect the model index "
            "(starting from 0).".format(snapshot, len(trajectory)))
    with open(output_path, "w") as fw:
        fw.write("MODEL     %4d\n" % (snapshot + 1))
        fw.write(PDB.pdb)
        fw.write("ENDMDL\n")
        fw.write("END\n")
Example #21
0
def main(epoch_num, trajectory, snapshot_num, resname, clustering_object,
         topology):
    calc = RMSDCalculator.RMSDCalculator()
    clustering_object = utilities.readClusteringObject(clustering_object)
    n_clusters = utilities.loadtxtfile(
        os.path.join(str(max(0, epoch_num - 1)), "clustering",
                     "summary.txt")).shape[0]
    if topology is not None:
        topology_contents = utilities.getTopologyFile(topology)
    else:
        topology_contents = None
    filename = glob.glob(
        os.path.join(str(epoch_num), "*traj*_%d.*" % trajectory))
    if not filename:
        raise ValueError(
            "No file with the specified epoch and trajectory found")
    try:
        snapshots = utilities.getSnapshots(filename[0],
                                           topology=topology)[snapshot_num]
    except IndexError:
        raise IndexError(
            "Snapshot number %d not found in trajectory %d for epoch %d, please check that the arguments provided are correct"
            % (snapshot_num, trajectory, epoch_num))
    pdb = atomset.PDB()
    pdb.initialise(snapshots, resname=resname, topology=topology_contents)
    for i, cluster in enumerate(clustering_object[:n_clusters]):
        dist = calc.computeRMSD(pdb, cluster.pdb)
        if dist < cluster.threshold:
            print("Snapshot belongs to cluster", i)
            return
    print("Snapshot not assigned to any cluster! :(")
def main(top, bot, radius, title="box.pdb", output="", n_points=10, input_pdb=None, center=None, type_box="cylinder"):
    if output:
        if not os.path.exists(output):
            os.makedirs(output)
        title = os.path.join(output, title)
    if input_pdb is not None:
        in_PDB = atomset.PDB()
        in_PDB.initialise(input_pdb, resname="DUM")
        for atom in in_PDB.atoms.values():
            if atom.name == "DUMT":
                top = atom.getAtomCoords()
            if atom.name == "DUMB":
                bot = atom.getAtomCoords()
            if atom.name == "DUM":
                center = atom.getAtomCoords()
    if type_box == "cylinder":
        if top is None or bot is None:
            raise utilities.RequiredParameterMissingException("Coordinates for the top and bottom base center not specified!!!")
        coords = generate_cylinder_box(top, bot, radius, n_points)
    elif type_box == "sphere":
        if center is None:
            raise utilities.RequiredParameterMissingException("Coordinates for the center not specified!!!")
        coords = generate_sphere_box(center, radius, n_points)
    coords = np.array(coords)
    utilities.write_PDB_clusters(coords, title)
Example #23
0
 def testIntegration3(self):
     """
         Simulations are actually run
     """
     controlFile = "tests/data/3ptb_data/integrationTest3.conf"
     goldenPath = "tests/data/3ptb_data/originTest3"
     outputPath = "tests/data/3ptb_data/Test3"
     elements = [22, 14, 16, 19, 1]
     goldenClusters = []
     metrics = [[1.00000e+00, 0.00000e+00, 0.00000e+00, -5.28675e+02, 6.41969e-03],
                [1.00000e+00, 0.00000e+00, 0.00000e+00, -5.28657e+02, 1.88599e-02],
                [1.00000e+00, 0.00000e+00, 0.00000e+00, -5.28675e+02, 6.41969e-03],
                [1.00000e+00, 0.00000e+00, 0.00000e+00, -5.28665e+02, 1.24213e-02],
                [1.00000e+00, 5.00000e+00, 5.00000e+00, -5.28660e+02, 1.75149e-02]]
     for i in range(5):
         pdb = atomset.PDB()
         pdb.initialise(goldenPath+"/2/clustering/cluster_%d.pdb" % i, resname="AEN")
         cluster = clustering.Cluster(pdb, 4, metrics=metrics[i])
         cluster.elements = elements[i]
         cluster.contacts = 0
         goldenClusters.append(cluster)
     # name = socket.gethostname()
     # if "bsccv" not in name and "login" not in name:
     #     print("Some integration can't be run due to not having PELE  installed")
     #     return True
     # self.integrationTest(controlFile, goldenPath, outputPath, goldenClusters)
     tmpFolder = "tmp_" + outputPath.replace("/", "_")
     adaptiveSampling.main(controlFile)
     self.check_succesful_simulation(outputPath, 3)
     # cleanup
     shutil.rmtree(outputPath)
     shutil.rmtree(tmpFolder)
Example #24
0
def getRMSD(traj, nativePDB, resname, symmetries, topology=None):
    """
        Computes the RMSD of a trajectory, given a native and symmetries

        :param traj: Trajecotry filename
        :type traj: str
        :param nativePDB:  Native PDB object
        :type native PDB: :py:class:`.PDB`
        :param resname: Resname to compute its RMSD
        :type resname: str
        :param symmetries: Symmetries dictionary list with independent symmetry groups
        :type symmetries: list of dict
        :param topology: Topology for non-pdb trajectories
        :type topology: list

        :return: np.array -- Array with the rmsd values of the trajectory
    """

    snapshots = getSnapshots(traj)
    rmsds = np.zeros(len(snapshots))
    RMSDCalc = RMSDCalculator.RMSDCalculator(symmetries)
    for i, snapshot in enumerate(snapshots):
        snapshotPDB = atomset.PDB()
        snapshotPDB.initialise(snapshot, resname=resname, topology=topology)

        rmsds[i] = RMSDCalc.computeRMSD(nativePDB, snapshotPDB)

    return rmsds
def main(trajectory, snapshot, epoch, outputPath, out_filename, topology):
    if outputPath is not None:
        outputPath = os.path.join(outputPath, "")
        if not os.path.exists(outputPath):
            os.makedirs(outputPath)
    else:
        outputPath = ""
    if topology is not None:
        topology_contents = utilities.getTopologyFile(topology)
    else:
        topology_contents = None
    if os.path.exists(outputPath + out_filename):
        # If the specified name exists, append a number to distinguish the files
        name, ext = os.path.splitext(out_filename)
        out_filename = "".join([name, "_%d", ext])
        i = 1
        while os.path.exists(outputPath + out_filename % i):
            i += 1
        out_filename %= i
    pathway = []
    # Strip out trailing backslash if present
    pathPrefix, epoch = os.path.split(epoch.rstrip("/"))
    sys.stderr.write("Creating pathway...\n")
    while True:
        filename = glob.glob(
            os.path.join(pathPrefix, epoch, "*traj*_%d.*" % trajectory))
        if not filename:
            raise ValueError(
                "Trajectory %s not found!" %
                os.path.join(pathPrefix, epoch, "*traj*_%d.*" % trajectory))
        snapshots = utilities.getSnapshots(filename[0])
        if epoch == '0':
            initial = 0
        else:
            # avoid repeating the initial snapshot
            initial = 1
        if not isinstance(snapshots[0], basestring):
            new_snapshots = []
            for i in range(initial, snapshot + 1):
                PDB = atomset.PDB()
                PDB.initialise(snapshots[i], topology=topology_contents)
                new_snapshots.append(PDB.pdb)
            snapshots = new_snapshots
        else:
            snapshots = snapshots[initial:snapshot + 1]
        pathway.insert(0, snapshots)
        if epoch == '0':
            # Once we get to epoch 0, we just need to append the trajectory
            # where the cluster was found and we can break out of the loop
            break
        procMapping = open(
            os.path.join(pathPrefix, epoch,
                         "processorMapping.txt")).read().rstrip().split(':')
        epoch, trajectory, snapshot = map(
            int, procMapping[trajectory - 1][1:-1].split(','))
        epoch = str(epoch)
    sys.stderr.write("Writing pathway...\n")
    with open(outputPath + out_filename, "a") as f:
        f.write("ENDMDL\n".join(itertools.chain.from_iterable(pathway)))
Example #26
0
def getLigandAlphaCarbonsCoords(allCoordinates, lig_resname):
    trajCoords = []
    for coordinates in allCoordinates:
        PDB = atomset.PDB()
        PDB.initialise(coordinates, resname=lig_resname)
        snapshotCoords = [
            coord for at in PDB.atomList
            for coord in PDB.atoms[at].getAtomCoords()
        ]
        PDBCA = atomset.PDB()
        PDBCA.initialise(coordinates, type="PROTEIN")
        snapshotCoords.extend([
            coord for at in PDBCA.atomList
            for coord in PDBCA.atoms[at].getAtomCoords()
        ])
        trajCoords.append(snapshotCoords)
    return trajCoords
Example #27
0
def get_min_Pos(native, resname):
    if native is not None:
        if resname is None:
            raise ValueError("Resname not specified!!")
        pdb_native = atomset.PDB()
        pdb_native.initialise(u"%s" % native, resname=resname)
        minim = pdb_native.getCOM()
    return minim
Example #28
0
 def test_PDB_interface_XTC(self):
     golden = "tests/data/ain_native_fixed.pdb"
     topology = utilities.getTopologyFile(golden)
     xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
     xtc = atomset.PDB()
     xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
     golden_pdb = atomset.PDB()
     golden_pdb.initialise(golden, resname="AIN")
     self.assertEqual(len(golden_pdb), len(xtc))
     atomList = [atom for atom in golden_pdb]
     atomList_xtc = [atom for atom in xtc]
     self.assertEqual(atomList, atomList_xtc)
     atomId = xtc.atomList[0]
     atom = xtc[atomId]
     self.assertEqual(atom, xtc.getAtom(atomId))
     xtc[atomId] = None
     self.assertEqual(None, xtc.getAtom(atomId))
Example #29
0
    def testPDB_RMSD_XTC(self):
        # preparation
        golden = "tests/data/ain_native_fixed.pdb"
        topology = utilities.getTopologyFile(golden)
        xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
        xtc = atomset.PDB()
        xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
        golden_pdb = atomset.PDB()
        golden_pdb.initialise(golden, resname="AIN")

        # assertion
        RMSDCalc = RMSDCalculator.RMSDCalculator()

        # function to test
        RMSD = RMSDCalc.computeRMSD(golden_pdb, xtc)
        golden_RMSD = 0.0000
        self.assertAlmostEqual(RMSD, golden_RMSD, 2)
Example #30
0
 def testPDB_RMSD_symmetries_XTC(self):
     # preparation
     golden = "tests/data/ain_native_fixed.pdb"
     topology = utilities.getTopologyFile(golden)
     xtc_obj = mdtraj.load("tests/data/ain_native_fixed.xtc", top=golden)
     xtc = atomset.PDB()
     xtc.initialise(10 * xtc_obj.xyz[0], resname="AIN", topology=topology)
     golden_pdb = atomset.PDB()
     golden_pdb.initialise(golden, resname="AIN")
     symDict = [{"1733:O1:AIN": "1735:O2:AIN"}]
     RMSDCalc = RMSDCalculator.RMSDCalculator(symDict)
     # function to test
     RMSD = RMSDCalc.computeRMSD(xtc, golden_pdb)
     reverseRMSD = RMSDCalc.computeRMSD(golden_pdb, xtc)
     golden_RMSD = 0.00000
     self.assertAlmostEqual(RMSD, reverseRMSD, 2)
     self.assertAlmostEqual(RMSD, golden_RMSD, 2)