Exemple #1
0
    def test_clone(self):
        chain1 = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])
        chain2 = chain1.clone()

        assert len(chain1.residues) == len(chain2.residues) and \
            chain1.residues[0].name == chain2.residues[0].name

        chain1.residues[0].name = 'MET'
        assert chain1.residues[0].name != chain2.residues[0].name
Exemple #2
0
 def test_clone(self):
     chain1 = Chain('A', [Residue('ALA',1), Residue('MET',2)])
     chain2 = chain1.clone()
     
     assert len(chain1.residues) == len(chain2.residues) and \
         chain1.residues[0].name == chain2.residues[0].name
     
     chain1.residues[0].name = 'MET'
     assert chain1.residues[0].name != chain2.residues[0].name
Exemple #3
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/'
Exemple #4
0
def parse_complex_from_file(input_file_name,
                            atoms_to_ignore=[],
                            verbose=False):
    """Reads and parses a given input_file_name PDB file.
    
    TODO: Check if chain have been already created and insert it into the first one
    """
    lines = open(input_file_name).readlines()
    atoms = []
    residues = []
    chains = []
    num_models = 0
    last_chain_id = '#'
    last_residue_name = '#'
    last_residue_number = '#'
    current_chain = None
    current_residue = None
    for line in lines:
        # Only first model is going to be read
        if num_models <= 1:
            line_type = line[0:6].strip()
            if line_type == "MODEL":
                num_models += 1
                if num_models > 1:
                    log.warning(
                        'Multiple models found in %s. Only first model will be used.'
                        % input_file_name)
            elif line_type == "ATOM" or line_type == "HETATM":
                try:
                    atom = read_atom_line(line, line_type, atoms_to_ignore)
                    atoms.append(atom)
                except PDBParsingWarning as warning:
                    if verbose:
                        print(warning)
                    continue

                if last_chain_id != atom.chain_id:
                    last_chain_id = atom.chain_id
                    current_chain = Chain(last_chain_id)
                    chains.append(current_chain)
                if last_residue_name != atom.residue_name or last_residue_number != atom.residue_number:
                    last_residue_name = atom.residue_name
                    last_residue_number = atom.residue_number
                    current_residue = Residue(atom.residue_name,
                                              atom.residue_number)
                    residues.append(current_residue)
                    current_chain.residues.append(current_residue)
                current_residue.atoms.append(atom)

    # Set backbone and side-chain atoms
    for residue in residues:
        residue.set_backbone_and_sidechain()
        try:
            residue.check()
        except Exception as e:
            log.warning("Possible problem: %s" % str(e))

    return atoms, residues, chains
Exemple #5
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'
Exemple #6
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()
Exemple #7
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()
Exemple #8
0
    def test__to_string(self):
        chain = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])

        assert "[Chain A]\nALA.1\nMET.2" == str(chain)
Exemple #9
0
 def test_create_chain(self):
     chain = Chain('A', [Residue('ALA', 1), Residue('MET', 2)])
     assert chain.cid == 'A' and len(chain.residues) == 2
Exemple #10
0
 def test_create_empty_chain(self):
     chain = Chain()
     assert chain.cid == '' and chain.peptide and len(chain.residues) == 0