Пример #1
0
 def test_distance(self):
     atom1 = Atom(1, 'CA', '', 'A', 'ALA', 1, '', x=1., y=2., z=2., 
                 occupancy=1., b_factor=0., element=None, mass=None)
     atom2 = Atom()
     
     assert_almost_equals(3.0, atom1.distance(atom2))
     assert_almost_equals(3.0, atom2.distance(atom1))
Пример #2
0
 def test_clone(self):
     atom1 = Atom()
     atom2 = atom1.clone()
     
     assert atom1 == atom2
     assert not atom1 != atom2
     
     atom1.name = 'C'
     
     assert atom1 != atom2
Пример #3
0
    def test_reference_points_singular_matrix(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom3 = Atom(3, 'C', '', 'A', 'ALA', x=1., y=1., z=1.)
        atoms = [atom1, atom2, atom3]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.], [0., 0., 0.], [1., 1., 1.]]))

        expected_coordinates = SpacePoints([[1., 1., 1.]])

        assert expected_coordinates == docking_model.reference_points
Пример #4
0
    def test_clone(self):
        atom1 = Atom()
        atom2 = atom1.clone()

        assert atom1 == atom2
        assert not atom1 != atom2

        atom1.name = 'C'

        assert atom1 != atom2
Пример #5
0
    def test_apply_restraints(self):
        swarm_centers = [[13.861446721229493, -28.730453433364488, 0.024305878079852336],
                         [-29.427540743780476, -2.960299745528308, -5.168493906227671],
                         [24.244162925019417, 2.9322386764307304, -15.44286271885186],
                         [2.0463687050893857, -13.94537658944639, -24.099372234598455],
                         [-10.833120242061193, 13.517315520348813, -20.69794891072167],
                         [-10.934383879949547, 24.302392364266915, 4.508648686944662],
                         [-13.742376304140548, -18.137915011405447, 12.54861921589357],
                         [-6.5003433948735, 7.824777098389764, 23.942006739050495],
                         [17.345254847698744, 18.209853942307866, 6.384609403593564],
                         [13.837506572006518, -7.152838167487336, 18.165186863034638]]
        distance_cutoff = 19.522956365520056
        translation = [-21.630461302211305, -5.510320024570013, -20.27116646191647]
        atoms = [Atom(atom_number=1, atom_name='N', x=25.344, y=-10.048, z=26.435),
                 Atom(atom_number=2, atom_name='CA', x=26.439, y=-10.798, z=26.994),
                 Atom(atom_number=3, atom_name='C', x=26.646, y=-12.135, z=26.328),
                 Atom(atom_number=4, atom_name='O', x=27.790, y=-12.531, z=26.028),
                 Atom(atom_number=5, atom_name='CB', x=26.230, y=-10.933, z=28.503),
                 Atom(atom_number=6, atom_name='CG', x=26.448, y=-9.540, z=29.191),
                 Atom(atom_number=7, atom_name='CD', x=26.283, y=-9.676, z=30.689),
                 Atom(atom_number=8, atom_name='CE', x=26.609, y=-8.392, z=31.454),
                 Atom(atom_number=9, atom_name='NZ', x=26.210, y=-8.498, z=32.884)]
        receptor_restraints = [Residue('LYS', 239, atoms=atoms)]

        expected_new_centers = [[13.861446721229493, -28.730453433364488, 0.024305878079852336],
                                [13.837506572006518, -7.152838167487336, 18.165186863034638]]

        new_centers = apply_restraints(swarm_centers, receptor_restraints, [], distance_cutoff, translation)

        assert np.allclose(expected_new_centers, new_centers)
Пример #6
0
 def test_reference_points_minimum_volume_ellipsoid(self):
     atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=1.2, y=-1., z=2.)
     atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
     atom3 = Atom(3, 'C', '', 'A', 'ALA', x=0.5, y=3., z=0.5)
     atom4 = Atom(4, 'N', '', 'A', 'ALA', x=0.85, y=-2.5, z=0.4)
     atoms = [atom1, atom2, atom3, atom4]
     docking_model = DockingModel(atoms, SpacePoints([[1.2, -1., 2.], [0., 0., 0.],
                                                      [0.5, 3., 0.5], [0.85, -2.5, 0.4]]))
     # Only center is used now
     expected_coordinates = SpacePoints([[0.6375, -0.125, 0.725]])
     assert expected_coordinates == docking_model.reference_points
Пример #7
0
    def test_get_atom(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        atom1 = residue.get_atom('CA')
        atom2 = residue.get_atom('N')
        atom3 = residue.get_atom('CG')

        assert 'CA' == atom1.name
        assert 'N' == atom2.name
        assert None == atom3
Пример #8
0
    def test_backbone_sidechain(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'),
                 Atom(2, 'N', '', 'A', 'ALA'),
                 Atom(3, 'C', '', 'A', 'ALA'),
                 Atom(4, 'O', '', 'A', 'ALA'),
                 Atom(5, 'CB', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        assert 1 == len(residue.sidechain)
        assert 'CB' == residue.sidechain[0].name
        assert 4 == len(residue.backbone)
Пример #9
0
    def test_get_atom(self):
        atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')]
        residue = Residue('ALA', 1, atoms)

        atom1 = residue.get_atom('CA')
        atom2 = residue.get_atom('N')
        atom3 = residue.get_atom('CG')

        assert atom1.name == "CA"
        assert atom2.name == "N"
        assert atom3 is None
Пример #10
0
    def test_backbone_sidechain(self):
        atoms = [
            Atom(1, 'CA', '', 'A', 'ALA'),
            Atom(2, 'N', '', 'A', 'ALA'),
            Atom(3, 'C', '', 'A', 'ALA'),
            Atom(4, 'O', '', 'A', 'ALA'),
            Atom(5, 'CB', '', 'A', 'ALA')
        ]
        residue = Residue('ALA', 1, atoms)

        assert len(residue.sidechain) == 1
        assert residue.sidechain[0].name == "CB"
        assert len(residue.backbone) == 4
Пример #11
0
    def test_translate(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        residues = [Residue('ALA', 1, [atom1, atom2])]
        docking_model = DockingModel(residues, SpacePoints([[2., 2., 2.], [0, 0, 0]]))

        docking_model.translate([-2, -2, -2])

        expected_coordinates = SpacePoints([[0, 0, 0], [-2, -2, -2]])
        assert expected_coordinates == docking_model.coordinates[0]

        expected_coordinates = SpacePoints([[-1, -1, -1]])
        assert np.allclose(expected_coordinates, docking_model.reference_points)
Пример #12
0
    def test_translate(self):
        atom1 = Atom(2, 'C', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'C', '', 'A', 'ALA', x=0., y=0., z=0.)
        residue = Residue('ALA', 1, [atom1, atom2])
        chains = [Chain('A', [residue])]
        protein = Complex(chains)

        com = protein.center_of_mass()
        protein.translate([c * -1 for c in com])

        expected_coordinates = np.array([[1, 1, 1], [-1, -1, -1]])

        assert (expected_coordinates == protein.atom_coordinates).all()
Пример #13
0
 def setUp(self):
     self.atoms1 = [
         Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
         Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
     ]
     self.atoms2 = [
         Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
         Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
     ]
     self.residues = [
         Residue('ALA', 1, self.atoms1),
         Residue('HIS', 2, self.atoms2)
     ]
Пример #14
0
    def test_null_rotation(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom2 = Atom(2, 'CB', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom3 = Atom(3, 'C', '', 'A', 'ALA', x=0.5, y=0.5, z=0.5)
        atoms = [atom1, atom2, atom3]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.], [0., 0., 0.], [0.5, 0.5, 0.5]]))
        q = Quaternion()
        docking_model.rotate(q)

        expected_coordinates = SpacePoints([[2., 2., 2.], [0., 0., 0.], [0.5, 0.5, 0.5]])
        assert expected_coordinates == docking_model.coordinates[0]

        expected_coordinates = SpacePoints([[0.833333333333, 0.833333333333, 0.833333333333]])
        assert np.allclose(expected_coordinates, docking_model.reference_points)
Пример #15
0
    def test_move_to_origin(self):
        atom1 = Atom(2, 'C', '', 'A', 'ALA', x=0., y=0., z=0.)
        atom2 = Atom(2, 'C', '', 'A', 'ALA', x=2., y=2., z=2.)
        atom3 = Atom(2, 'C', '', 'A', 'ALA', x=4., y=4., z=4.)
        residue = Residue('ALA', 1, [atom1, atom2, atom3])
        chains = [Chain('A', [residue])]
        protein = Complex(chains)

        protein.move_to_origin()

        expected_coordinates = np.array([[-2., -2., -2.], [0, 0, 0],
                                         [2., 2., 2.]])

        assert (expected_coordinates == protein.atom_coordinates).all()
Пример #16
0
    def test_null_rotation_one_atom(self):
        atom1 = Atom(1, 'CA', '', 'A', 'ALA', x=2., y=2., z=2.)
        atoms = [atom1]
        docking_model = DockingModel(atoms, SpacePoints([[2., 2., 2.]]))
        q = Quaternion()
        docking_model.rotate(q)

        expected_coordinates = np.array([[2., 2., 2.]])
        assert (expected_coordinates == docking_model.coordinates).all()
Пример #17
0
def read_atom_line(line, line_type='', atoms_to_ignore=[]):
    """Parses a PDB file line starting with 'ATOM' or 'HETATM'"""
    element = cstrip(line[76:78])
    try:
        x = float(line[30:38])
        y = float(line[38:46])
        z = float(line[46:54])
        
        if math.isnan(x) or math.isnan(y) or math.isnan(z):
            raise Exception()
    except:
        raise PDBParsingError("Wrong coordinates in '%s'" % line)

    try:
        atom_number = int(line[6:11])
    except ValueError:
        raise PDBParsingError("Wrong atom number in '%s'" % line)
    
    atom_name = cstrip(line[12:16])
    atom_alternative = cstrip(line[16])
    residue_name = cstrip(line[17:21])
    chain_id = cstrip(line[21])
    residue_ext = line[26]
    
    try:
        residue_number = int(line[22:26])
    except ValueError:
        raise PDBParsingError("Wrong residue number in '%s'" % line)
    
    if ('H' in atoms_to_ignore and atom_name[0] == 'H') or atom_name in atoms_to_ignore:
        raise PDBParsingWarning("Ignored atom %s.%s.%s %s" % (chain_id, 
                                                              residue_name, 
                                                              residue_number, 
                                                              atom_name))

    try:
        occupancy = float(line[54:60])
    except:
        occupancy = 1.0
        
    try:
        b_factor = float(line[60:66])
    except:
        b_factor = 0.0
    
    if not line_type:
        line_type = line[0:6].strip()
    
    if line_type == 'ATOM':
        return Atom(atom_number, atom_name, atom_alternative, chain_id,
                    residue_name, residue_number, residue_ext, 
                    x, y, z, occupancy, b_factor, element)
    else:
        return HetAtom(atom_number, atom_name, atom_alternative, chain_id,
                       residue_name, residue_number, residue_ext, 
                       x, y, z, occupancy, b_factor, element)
Пример #18
0
    def test_apply_restraints_only_blocking(self):
        swarm_centers = [
            [13.861446721229493, -28.730453433364488, 0.024305878079852336],
            [-29.427540743780476, -2.960299745528308, -5.168493906227671],
            [24.244162925019417, 2.9322386764307304, -15.44286271885186],
            [2.0463687050893857, -13.94537658944639, -24.099372234598455],
            [-10.833120242061193, 13.517315520348813, -20.69794891072167],
            [-10.934383879949547, 24.302392364266915, 4.508648686944662],
            [-13.742376304140548, -18.137915011405447, 12.54861921589357],
            [-6.5003433948735, 7.824777098389764, 23.942006739050495],
            [17.345254847698744, 18.209853942307866, 6.384609403593564],
            [13.837506572006518, -7.152838167487336, 18.165186863034638]
        ]
        distance_cutoff = 19.522956365520056
        translation = [
            -21.630461302211305, -5.510320024570013, -20.27116646191647
        ]

        atoms = [
            Atom(atom_number=1, atom_name='N', x=30.795, y=-14.563, z=19.577),
            Atom(atom_number=2, atom_name='CA', x=30.969, y=-13.948, z=18.287),
            Atom(atom_number=3, atom_name='C', x=32.148, y=-12.988, z=18.291),
            Atom(atom_number=4, atom_name='O', x=32.601, y=-12.684, z=19.413),
            Atom(atom_number=5, atom_name='CB', x=29.742, y=-13.163, z=17.861),
            Atom(atom_number=6, atom_name='CG', x=28.586, y=-14.066, z=17.510),
            Atom(atom_number=7, atom_name='OD1', x=28.470, y=-14.548,
                 z=16.359),
            Atom(atom_number=8, atom_name='ND2', x=27.742, y=-14.322, z=18.456)
        ]
        blocking_restraints = [Residue('ASN', 245, atoms=atoms)]
        expected_new_centers = [
            [-29.427540743780476, -2.960299745528308, -5.168493906227671],
            [24.244162925019417, 2.9322386764307304, -15.44286271885186],
            [2.0463687050893857, -13.94537658944639, -24.099372234598455],
            [-10.833120242061193, 13.517315520348813, -20.69794891072167],
            [-10.934383879949547, 24.302392364266915, 4.508648686944662],
            [-13.742376304140548, -18.137915011405447, 12.54861921589357],
            [-6.5003433948735, 7.824777098389764, 23.942006739050495],
            [17.345254847698744, 18.209853942307866, 6.384609403593564],
            [13.837506572006518, -7.152838167487336, 18.165186863034638]
        ]

        new_centers = apply_restraints(swarm_centers, [], blocking_restraints,
                                       distance_cutoff, translation)

        assert np.allclose(expected_new_centers, new_centers)
Пример #19
0
 def test_to_string(self):
     atom1 = Atom(1,
                  'CA',
                  '',
                  'A',
                  'ALA',
                  1,
                  '',
                  x=1.,
                  y=2.,
                  z=2.,
                  occupancy=1.,
                  b_factor=0.,
                  element=None,
                  mass=None)
     assert "  CA   1.000   2.000   2.000" == str(atom1)
Пример #20
0
 def test_assign_element_and_mass_of_not_recognized_element(self):
     atom = Atom(1,
                 'Ty',
                 '',
                 'A',
                 'BSG',
                 1,
                 '',
                 x=0.,
                 y=0.,
                 z=0.,
                 occupancy=1.,
                 b_factor=0.,
                 element=None,
                 mass=None)
     assert atom.name != 'Ty'
Пример #21
0
 def test_assign_element_and_mass(self):
     atom = Atom(1,
                 'CA',
                 '',
                 'A',
                 'ALA',
                 1,
                 '',
                 x=0.,
                 y=0.,
                 z=0.,
                 occupancy=1.,
                 b_factor=0.,
                 element=None,
                 mass=None)
     assert 'C' == atom.element
     assert_almost_equals(Atom.MASSES[atom.element], atom.mass)
Пример #22
0
 def test_create_atom_not_given_element(self):
     atom = Atom(1,
                 'PB',
                 '',
                 'A',
                 'ALA',
                 1,
                 '',
                 x=0.,
                 y=0.,
                 z=0.,
                 occupancy=1.,
                 b_factor=0.,
                 element=None,
                 mass=None)
     assert 'PB' == atom.element
     assert_almost_equals(Atom.MASSES[atom.element], atom.mass)
Пример #23
0
 def test_not_recognized_element(self):
     """Test if Tylium is recognized"""
     atom = Atom(1,
                 'Ty',
                 '',
                 'A',
                 'BSG',
                 1,
                 '',
                 x=0.,
                 y=0.,
                 z=0.,
                 occupancy=1.,
                 b_factor=0.,
                 element='Ty',
                 mass=None)
     assert atom.name != 'Ty'
Пример #24
0
    def test_is_hydrogen(self):
        atom1 = Atom(1,
                     'CA',
                     '',
                     'A',
                     'ALA',
                     1,
                     '',
                     x=1.,
                     y=2.,
                     z=-3.,
                     occupancy=1.,
                     b_factor=0.,
                     element=None,
                     mass=None)
        atom2 = Atom()

        assert not atom1.is_hydrogen() and atom2.is_hydrogen()
Пример #25
0
    def test_distance(self):
        atom1 = Atom(1,
                     'CA',
                     '',
                     'A',
                     'ALA',
                     1,
                     '',
                     x=1.,
                     y=2.,
                     z=2.,
                     occupancy=1.,
                     b_factor=0.,
                     element=None,
                     mass=None)
        atom2 = Atom()

        assert_almost_equals(3.0, atom1.distance(atom2))
        assert_almost_equals(3.0, atom2.distance(atom1))
Пример #26
0
    def setUp(self):
        self.atoms1 = [
            Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
            Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
        ]
        self.atoms2 = [
            Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
            Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
        ]
        self.residues = [
            Residue('ALA', 1, self.atoms1),
            Residue('HIS', 2, self.atoms2)
        ]
        self.chains = [Chain('A', self.residues)]

        self.atoms3 = [
            Atom(1, 'N', '', 'A', 'CYS', 3, x=2.496, y=13.096, z=10.611),
            Atom(2, 'CA', '', 'A', 'CYS', 3, x=2.787, y=12.161, z=9.557),
            Atom(3, 'C', '', 'A', 'CYS', 3, x=4.052, y=11.431, z=9.896),
            Atom(4, 'O', '', 'A', 'CYS', 3, x=5.120, y=12.044, z=9.912),
            Atom(5, 'CB', '', 'A', 'CYS', 3, x=2.879, y=12.853, z=8.246),
            Atom(6, 'SG', '', 'A', 'CYS', 3, x=3.492, y=11.911, z=6.838)
        ]

        self.atoms4 = [
            Atom(7, 'N', '', 'A', 'PRO', 4, x=3.987, y=10.183, z=10.286),
            Atom(8, 'CA', '', 'A', 'PRO', 4, x=5.219, y=9.484, z=10.695),
            Atom(9, 'C', '', 'A', 'PRO', 4, x=6.277, y=9.424, z=9.662),
            Atom(10, 'O', '', 'A', 'PRO', 4, x=5.993, y=9.385, z=8.431),
            Atom(11, 'CB', '', 'A', 'PRO', 4, x=4.664, y=8.140, z=11.092),
            Atom(12, 'CG', '', 'A', 'PRO', 4, x=3.295, y=8.087, z=10.812),
            Atom(13, 'CD', '', 'A', 'PRO', 4, x=2.797, y=9.351, z=10.427)
        ]
        self.residues2 = [
            Residue('CYS', 1, self.atoms3),
            Residue('PRO', 2, self.atoms4)
        ]
        self.chains2 = [Chain('A', self.residues2)]

        self.path = os.path.dirname(os.path.realpath(__file__))
        self.test_path = self.path + '/scratch/'
        try:
            shutil.rmtree(self.test_path)
        except:
            pass
        os.mkdir(self.test_path)
        self.golden_data_path = os.path.normpath(
            os.path.dirname(os.path.realpath(__file__))) + '/golden_data/'
Пример #27
0
 def test_create_empty_atom(self):
     atom = Atom()
     assert_almost_equals(0.0, atom.x)
Пример #28
0
    def __init__(self):
        self.atoms1 = [
            Atom(1, 'CA', '', 'A', 'ALA', x=1., y=1., z=1.),
            Atom(2, 'N', '', 'A', 'ALA', x=2., y=2., z=2.)
        ]
        self.atoms2 = [
            Atom(3, 'CA', '', 'A', 'HIS', x=1.1, y=1.2, z=1.3),
            Atom(4, 'N', '', 'A', 'HIS', x=2.9, y=2.8, z=2.7)
        ]
        self.residues = [
            Residue('ALA', 1, self.atoms1),
            Residue('HIS', 2, self.atoms2)
        ]
        self.chains = [Chain('A', self.residues)]

        self.atoms3 = [
            Atom(1, 'N', '', 'A', 'CYS', 3, x=2.496, y=13.096, z=10.611),
            Atom(2, 'CA', '', 'A', 'CYS', 3, x=2.787, y=12.161, z=9.557),
            Atom(3, 'C', '', 'A', 'CYS', 3, x=4.052, y=11.431, z=9.896),
            Atom(4, 'O', '', 'A', 'CYS', 3, x=5.120, y=12.044, z=9.912),
            Atom(5, 'CB', '', 'A', 'CYS', 3, x=2.879, y=12.853, z=8.246),
            Atom(6, 'SG', '', 'A', 'CYS', 3, x=3.492, y=11.911, z=6.838)
        ]

        self.atoms4 = [
            Atom(7, 'N', '', 'A', 'PRO', 4, x=3.987, y=10.183, z=10.286),
            Atom(8, 'CA', '', 'A', 'PRO', 4, x=5.219, y=9.484, z=10.695),
            Atom(9, 'C', '', 'A', 'PRO', 4, x=6.277, y=9.424, z=9.662),
            Atom(10, 'O', '', 'A', 'PRO', 4, x=5.993, y=9.385, z=8.431),
            Atom(11, 'CB', '', 'A', 'PRO', 4, x=4.664, y=8.140, z=11.092),
            Atom(12, 'CG', '', 'A', 'PRO', 4, x=3.295, y=8.087, z=10.812),
            Atom(13, 'CD', '', 'A', 'PRO', 4, x=2.797, y=9.351, z=10.427)
        ]
        self.residues2 = [
            Residue('CYS', 1, self.atoms3),
            Residue('PRO', 2, self.atoms4)
        ]
        self.chains2 = [Chain('A', self.residues2)]

        self.path = Path(__file__).absolute().parent
        self.test_path = self.path / 'scratch_complex'
        self.golden_data_path = self.path / 'golden_data'
Пример #29
0
 def test_to_string(self):
     atoms = [Atom(1, 'CA', '', 'A', 'ALA'), Atom(2, 'N', '', 'A', 'ALA')] 
     residue = Residue('ALA', 1, atoms)
     assert "ALA.1    CA   0.000   0.000   0.000\nALA.1     N   0.000   0.000   0.000" == str(residue)
Пример #30
0
 def test_create_residue_with_atoms(self):
     residue = Residue('ALA', 1, [Atom(), Atom()])
     assert residue.name == 'ALA' and residue.number == 1 and len(residue.atoms) == 2
Пример #31
0
 def dummy(x=0., y=0., z=0.):
     atom = Atom(atom_name='CA', residue_name='DUM', x=x, y=y, z=z)
     return Residue(residue_name='DUM', residue_number=0, atoms=[atom])
Пример #32
0
 def test_is_backbone(self):
     atom1 = Atom(1, 'CA', '', 'A', 'ALA', 1, '', x=1., y=2., z=-3., 
                 occupancy=1., b_factor=0., element=None, mass=None)
     atom2 = Atom()
     
     assert atom1.is_backbone() and not atom2.is_backbone()