IMP  2.4.0
The Integrative Modeling Platform
rotamer_pdb2.py
1 ## \example rotamer/rotamer_pdb2.py
2 # rotamer_pdb.py is a script demonstrating the usage of
3 # RotamerCalculator and RotamerLibrary. It reads a PDB file and a
4 # rotamer library file, and tries to rotate the atoms based on the
5 # most probable chi angles from the rotamer library. Then it saves
6 # the rotated atoms to a specified output PDB file.
7 #
8 # Usage:
9 #
10 # `python rotamer_pdb.py -i <input>.pdb -l <rotamer_library>.lib -o <output>.pdb`
11 #
12 # Example (the result will be saved into transformed_1z5s_A.pdb):
13 #
14 # `../../../tools/imppy.sh python rotamer_pdb.py -i ../../atom/test/input/1z5s_A.pdb \
15 # -l /path/to/ALL.bbdep.rotamers.lib -o transformed_1z5s_A.pdb`
16 #
17 
18 #!/usr/bin/env python
19 
20 from __future__ import print_function
21 import IMP
22 import IMP.base
23 import IMP.core
24 import IMP.atom
25 import IMP.algebra
26 import IMP.rotamer
27 
28 
29 def transform(input_pdb, input_lib, output_pdb):
30  # read rotamer library
32  rl.read_library_file(input_lib)
34 
35  # read the original PDB
36  m = IMP.kernel.Model()
37  orig_h = IMP.atom.read_pdb(input_pdb, m)
38  mh = IMP.atom.get_by_type(orig_h, IMP.atom.RESIDUE_TYPE)
39 
40  # transform...
42  rc.transform(orig_h, hps, 0.9, 1e-6, 6)
43 
44  # save the rotated atoms to output PDB
45  IMP.atom.write_pdb(orig_h, output_pdb)
46 
47 
48 def quick_test():
51  rc.set_was_used(True)
52 
53 
54 if __name__ == '__main__':
55 
56  import sys
57 
58  P = IMP.OptionParser()
59  P.add_option('--input_pdb', '-i', action='store', type='string',
60  help='input PDB file (required)')
61  P.add_option('--input_lib', '-l', action='store', type='string',
62  help='input rotamer library file (required)')
63  P.add_option('--output_pdb', '-o', action='store', type='string',
64  help='output PDB file (required)')
65  P.add_option('--verbose', '-v', action='store_true',
66  help='show more messages')
67  opts, args = P.parse_args()
68  if IMP.base.get_bool_flag('run_quick_test') or \
69  not (opts.input_pdb or opts.input_lib or opts.output_pdb):
70  quick_test()
71  sys.exit(0)
72  if not opts.input_pdb:
73  print('--input_pdb is required')
74  sys.exit(1)
75  if not opts.output_pdb:
76  print('--output_pdb is required')
77  sys.exit(1)
78  if not opts.input_lib:
79  print('--input_lib is required')
80  sys.exit(1)
81  if opts.verbose:
82  IMP.base.set_log_level(IMP.base.VERBOSE)
83  else:
84  IMP.base.set_log_level(IMP.base.SILENT)
85  transform(opts.input_pdb, opts.input_lib, opts.output_pdb)
void write_pdb(const Selection &mhd, base::TextOutput out, unsigned int model=1)
IMP-specific subclass of optparse.OptionParser.
void set_log_level(LogLevel l)
Set the current global log level.
A class storing a whole rotamer library read from a file.
bool get_bool_flag(std::string name)
Low level functionality (logging, error handling, profiling, command line flags etc) that is used by ...
void transform(Hierarchy h, const algebra::Transformation3D &tr)
Transform a hierarchy. This is aware of rigid bodies.
A class performing the rotations of atoms in the residues.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Sampling of sidechain rotamers.
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.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73