IMP  2.0.0
The Integrative Modeling Platform
rotamer_pdb2.py
1 ## \example modules/rotamer/examples/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 import IMP
20 import IMP.core
21 import IMP.atom
22 import IMP.algebra
23 import IMP.rotamer
24 
25 
26 def transform(input_pdb, input_lib, output_pdb):
27  # read rotamer library
29  rl.read_library_file(input_lib)
31 
32  # read the original PDB
33  m = IMP.Model()
34  orig_h = IMP.atom.read_pdb(input_pdb, m)
35  mh = IMP.atom.get_by_type(orig_h, IMP.atom.RESIDUE_TYPE)
36 
37  # transform...
39  rc.transform(orig_h, hps, 0.9, 1e-6, 6)
40 
41  # save the rotated atoms to output PDB
42  IMP.atom.write_pdb(orig_h, output_pdb)
43 
44 
45 def quick_test():
48  rc.set_was_used(True)
49 
50 
51 if __name__ == '__main__':
52 
53  import sys
54  import optparse
55 
56  P = optparse.OptionParser()
57  P.add_option('--input_pdb', '-i', action='store', type='string',
58  help='input PDB file (required)')
59  P.add_option('--input_lib', '-l', action='store', type='string',
60  help='input rotamer library file (required)')
61  P.add_option('--output_pdb', '-o', action='store', type='string',
62  help='output PDB file (required)')
63  P.add_option('--verbose', '-v', action='store_true',
64  help='show more messages')
65  P.add_option('--run_quick_test', action='store_true',
66  help='run quick test')
67  opts, args = P.parse_args()
68  if opts.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)