IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
rotamer_pdb.py
1 ## \example rotamer/rotamer_pdb.py
2 # rotamer_pdb.py is a script demonstrating the usage of RotamerCalculator and RotamerLibrary.
3 # It reads a PDB file and a rotamer library file, and tries to rotate the atoms based on the most
4 # probable chi angles from the rotamer library. Then it saves the rotated atoms to a specified output
5 # PDB file.
6 #
7 # Usage:
8 #
9 # `python rotamer_pdb.py -i <input>.pdb -l <rotamer_library>.lib -o <output>.pdb`
10 #
11 # Example (the result will be saved into transformed_1z5s_A.pdb):
12 #
13 # `../../../tools/imppy.sh python rotamer_pdb.py -i ../../atom/test/input/1z5s_A.pdb \
14 # -l /path/to/ALL.bbdep.rotamers.lib -o transformed_1z5s_A.pdb`
15 #
16 
17 #!/usr/bin/env python
18 
19 from __future__ import print_function
20 import IMP
21 import IMP.core
22 import IMP.atom
23 import IMP.algebra
24 import IMP.rotamer
25 
26 
27 def transform(input_pdb, input_lib, output_pdb):
28  # read the original PDB
29  m = IMP.Model()
30  orig_h = IMP.atom.read_pdb(input_pdb, m)
31  mh = IMP.atom.get_by_type(orig_h, IMP.atom.RESIDUE_TYPE)
32 
33  # read rotamer library
35  rl.read_library_file(input_lib)
37 
38  # get the most probable rotamers
39  rotamers = list()
40  for h in mh:
41  rd = IMP.atom.Residue(h)
42  rr = rc.get_rotamer(rd, 0.01)
43  rotamers.append((rd, rr))
44 
45  # now set the coordinates of all atoms in the residues to the rotated
46  # coordinates
47  for rd, rr in rotamers:
48  for h in IMP.atom.get_by_type(rd, IMP.atom.ATOM_TYPE):
49  at = IMP.atom.Atom(h)
50  at_t = at.get_atom_type()
51  if rr.get_atom_exists(at_t):
52  # some atoms might not be rotated
53  idx = min(rr.get_number_of_cases(at_t) - 1, 1)
54  v = rr.get_coordinates(idx, at_t)
55  xyz = IMP.core.XYZ(at)
56  xyz.set_coordinates(v)
57 
58  # save the rotated atoms to output PDB
59  IMP.atom.write_pdb(orig_h, output_pdb)
60 
61 
62 def quick_test():
65  rc.set_was_used(True)
66 
67 
68 if __name__ == '__main__':
69 
70  import sys
71 
72  P = IMP.ArgumentParser()
73  P.add_argument('--input_pdb', '-i', action='store',
74  help='input PDB file (required)')
75  P.add_argument('--input_lib', '-l', action='store',
76  help='input rotamer library file (required)')
77  P.add_argument('--output_pdb', '-o', action='store',
78  help='output PDB file (required)')
79  P.add_argument('--verbose', '-v', action='store_true',
80  help='show more messages')
81  args = P.parse_args()
82  if IMP.get_bool_flag('run_quick_test') or \
83  not (args.input_pdb or args.input_lib or args.output_pdb):
84  quick_test()
85  sys.exit(0)
86  if not args.input_pdb:
87  print('--input_pdb is required')
88  sys.exit(1)
89  if not args.output_pdb:
90  print('--output_pdb is required')
91  sys.exit(1)
92  if not args.input_lib:
93  print('--input_lib is required')
94  sys.exit(1)
95  if args.verbose:
96  IMP.set_log_level(IMP.VERBOSE)
97  else:
98  IMP.set_log_level(IMP.SILENT)
99  transform(args.input_pdb, args.input_lib, args.output_pdb)
A class storing a whole rotamer library read from a file.
bool get_bool_flag(std::string name)
void write_pdb(const Selection &mhd, TextOutput out, unsigned int model=1)
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
void transform(Hierarchy h, const algebra::Transformation3D &tr)
Transform a hierarchy. This is aware of rigid bodies.
A decorator for a particle representing an atom.
Definition: atom/Atom.h:234
A class performing the rotations of atoms in the residues.
Sampling of sidechain rotamers.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
void set_log_level(LogLevel l)
Set the current global log level.
A decorator for a residue.
Definition: Residue.h:134
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Functionality for loading, creating, manipulating and scoring atomic structures.