comparison BioPDB_align_and_rmsd.py @ 0:6352d6dd74e2 draft default tip

planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit b90c5ab8f15397299e8baf2e903a9911c44d7668
author chemteam
date Thu, 06 Jun 2024 07:09:14 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6352d6dd74e2
1 #!/usr/bin/env python3
2
3 # The MIT License
4 #
5 # Copyright (c) 2010-2016 Anders S. Christensen
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 # THE SOFTWARE.
24
25 import argparse
26
27 import Bio.PDB
28
29
30 def __main__():
31 parser = argparse.ArgumentParser(
32 description='Residues to be aligned')
33 parser.add_argument(
34 '--start_residue', default=None,
35 help='start residue')
36 parser.add_argument(
37 '--end_residue', default=None,
38 help='end residue')
39 parser.add_argument(
40 '--ref_structure', default=None,
41 help='reference structure')
42 parser.add_argument(
43 '--model', default=None,
44 help='model structure')
45 parser.add_argument(
46 '--aligned_structure', default=None,
47 help='aligned structure')
48 parser.add_argument(
49 '--rmsd', default=None,
50 help='rmsd')
51 args = parser.parse_args()
52
53 # Select what residues numbers you wish to align
54 # and put them in a list
55 start_id = int(args.start_residue)
56 end_id = int(args.end_residue)
57 atoms_to_be_aligned = range(start_id, end_id + 1)
58
59 # Start the parser
60 pdb_parser = Bio.PDB.PDBParser(QUIET=True)
61
62 # Get the structures
63 ref_structure = pdb_parser.get_structure("reference", args.ref_structure)
64 sample_structure = pdb_parser.get_structure("sample", args.model)
65
66 # Use the first model in the pdb-files for alignment
67 # Change the number 0 if you want to align to another structure
68 ref_model = ref_structure[0]
69 sample_model = sample_structure[0]
70
71 # Make a list of the atoms (in the structures) you wish to align.
72 # In this case we use CA atoms whose index is in the specified range
73 ref_atoms = []
74 sample_atoms = []
75
76 # Iterate of all chains in the model in order to find all residues
77 for ref_chain in ref_model:
78 # Iterate of all residues in each model in order to find proper atoms
79 for ref_res in ref_chain:
80 # Check if residue number ( .get_id() ) is in the list
81 if ref_res.get_id()[1] in atoms_to_be_aligned:
82 # Append CA atom to list
83 ref_atoms.append(ref_res['CA'])
84
85 # Do the same for the sample structure
86 for sample_chain in sample_model:
87 for sample_res in sample_chain:
88 if sample_res.get_id()[1] in atoms_to_be_aligned:
89 sample_atoms.append(sample_res['CA'])
90
91 # Now we initiate the superimposer:
92 super_imposer = Bio.PDB.Superimposer()
93 super_imposer.set_atoms(ref_atoms, sample_atoms)
94 super_imposer.apply(sample_model.get_atoms())
95
96 # Save RMSD into an output file:
97 with open(args.rmsd, 'w') as rmsd_out:
98 rmsd_out.write(str(super_imposer.rms))
99
100 # Save aligned coordinates of the model:
101 io = Bio.PDB.PDBIO()
102 io.set_structure(sample_structure)
103 io.save(args.aligned_structure)
104
105
106 if __name__ == "__main__":
107 __main__()