Exemple #1
0
    def load_topology(self, pdb_id):

        pdb_file = os.path.abspath(
            os.path.join(currpath, '../files/{0}.pdb'.format(pdb_id)))
        mol_file = os.path.abspath(
            os.path.join(currpath, '../files/{0}.mol2'.format(pdb_id)))

        top = System(pdb_file, mol2file=mol_file).topology
        top.distances()

        return top
    def test_load_topology_sybyl(self):
        """
        Load topology including Tripos SYBYL atom types from mol2
        """

        top = System(self.pdb_file, mol2file=self.mol_file).topology
        self.assertTrue('attype' in top.columns)
    def test_load_topology_instance(self):
        """
        Check if returned object is instance of DataFrame, TopologyDataFrame
        """

        top = System(self.pdb_file).topology

        self.assertIsInstance(top, DataFrame)
        self.assertIsInstance(top, TopologyDataFrame)
Exemple #4
0
    def setUpClass(cls):
        """
        Prepare TopologyDataFrame once for every test
        """

        cls.top = System(cls.pdb_file, mol2file=cls.mol_file).topology

        # Build distance matrix
        cls.top.distances()
    def test_load_topology_pdb(self):
        """
        Load PDB file
        """

        top = System(self.pdb_file).topology

        self.assertEqual(len(top), 5202)
        self.assertEqual(list(top.columns), ['serial', 'name', 'element', 'resSeq', 'resName',
                                             'chainID', 'segmentID'])
Exemple #6
0
    def test_topdataframe_neighbours_exceptions(self):
        """
        Neighbours method exceptions
        """

        # Method requires pairwise distance matrix
        top = System(self.pdb_file, mol2file=self.mol_file).topology
        sel = top[top['resName'] == 'THA']
        self.assertRaises(AttributeError, sel.neighbours)

        # Target selection should be contained in parent
        sel.distances()
        target = top[top['resSeq'].isin(
            [72, 80, 81, 84, 85, 117, 118, 119, 121, 122])]
        parent = top[top['resSeq'].isin([84, 85, 117, 118, 119, 121, 122])]
        sel._parent = parent
        self.assertRaises(TypeError, sel.neighbours, target)
    def setUpClass(cls):
        """
        Prepare TopologyDataFrame once for every test
        """

        pdb_file = '{0}/{1}.pdb'.format(filepath, cls.ref['pdb_id'])
        mol_file = '{0}/{1}.mol2'.format(filepath, cls.ref['pdb_id'])

        # Load structures (PDB + MOL2) and calculate distance matrix
        trajectory = System(pdb_file, mol2file=mol_file)
        cls.top = trajectory.topology
        cls.top.distances()

        # Select ligand and neighbours, build contact frame
        if 'chain' in cls.ref:
            ligand_selection = cls.top[
                (cls.top['resSeq'] == cls.ref['ligand'])
                & (cls.top['chainID'] == cls.ref['chain'])]
        else:
            ligand_selection = cls.top[cls.top['resSeq'] == cls.ref['ligand']]

        cls.neighbour_selection = ligand_selection.neighbours()
        cls.cf = ligand_selection.contacts(cls.neighbour_selection)
Exemple #8
0
    def setUp(self):
        """
        Prepare TopologyDataFrame once for every test
        """

        self.top = System(self.pdb_file, mol2file=self.mol_file).topology
Exemple #9
0
class DistanceMatrixTests(UnittestPythonCompatibility):
    currpath = os.path.dirname(__file__)
    pdb_file = os.path.abspath(os.path.join(currpath, '../files/1acj.pdb'))
    mol_file = os.path.abspath(os.path.join(currpath, '../files/1acj.mol2'))

    def setUp(self):
        """
        Prepare TopologyDataFrame once for every test
        """

        self.top = System(self.pdb_file, mol2file=self.mol_file).topology

    def test_distmat_overflow_exception(self):
        """
        Test OverflowError exception for (too) large distance matrix
        """

        # Unable to compute distance matrix > max_distmat_size
        self.assertRaises(OverflowError,
                          self.top.distances,
                          max_distmat_size=10000)

    def test_distmat_attribute_exception(self):
        """
        Test AttributeError on missing or incomplete coordinates
        """

        # No coordinates
        self.top._coordinates = None
        self.assertRaises(AttributeError, self.top.distances)

    def test_distmat_square(self):
        """
        Test computation of default square matrix
        """

        distmat = self.top.distances()

        self.assertIsInstance(distmat, DataFrame)
        self.assertEqual(distmat.shape[0], distmat.shape[1])
        self.assertEqual(list(distmat.columns), list(distmat.index))

    def test_distmat_target(self):
        """
        Test computation of matrix with custom source and target selection
        """

        source = self.top[self.top['resSeq'] == 999]
        target = self.top[self.top['resName'] == 'HIS']
        distmat = source.distances(target=target)

        self.assertIsInstance(distmat, DataFrame)
        self.assertEqual(distmat.shape, (17, 138))
        self.assertEqual(len(distmat.columns), len(target))
        self.assertEqual(len(distmat.index), len(source))

    def test_distmat_empty_selection(self):
        """
        Test compuation of matrix when (one of) the input selections is empty
        """

        source = self.top[self.top['resSeq'] == 9999]
        target = self.top[self.top['resName'] == 'HIS']

        self.assertTrue(source.distances().empty)
        self.assertTrue(source.distances(target=target).empty)
    def setUpClass(cls):
        """
        Prepare TopologyDataFrame once for every test
        """

        cls.top = System(cls.pdb_file, mol2file=cls.mol_file).topology