RMF
add_bonds.py
1 ## \example add_bonds.py
2 # Show how to add bonds to a file.
3 from __future__ import print_function
4 import RMF
5 
6 
7 def copy_to_residues(pin, pout, rcf, rf, pcf, pf, acf, af, ccf, cf, bf, prev):
8  if rcf.get_is(pin):
9  rpin = rcf.get(pin)
10  rpout = rf.get(pout)
11  rpout.set_residue_type(rpin.get_residue_type())
12  rpout.set_residue_index(rpin.get_residue_index())
13  mass = 0
14  # provide a default for nonstandard residues
15  ca = pin.get_children()[0]
16  for c in pin.get_children():
17  # there is a hetatom
18  if acf.get_is(c) and c.get_name().find("CA") != -1:
19  ca = c
20  mass += pcf.get(c).get_mass()
21  ppout = pf.get(pout)
22  pca = pcf.get(ca)
23  ppout.set_coordinates(pca.get_coordinates())
24  ppout.set_mass(mass)
25  ppout.set_radius(3) # garbage value
26  if prev:
27  bd = bf.get(pout.add_child("bond", RMF.BOND))
28  bd.set_bonded_0(prev.get_id().get_index())
29  bd.set_bonded_1(pout.get_id().get_index())
30  prev = pout
31  else:
32  if ccf.get_is(pin):
33  cf.get(pout).set_chain_id(ccf.get(pin).get_chain_id())
34  prev = None
35  for inch in pin.get_children():
36  if inch.get_type() == RMF.REPRESENTATION:
37  outch = pout.add_child(inch.get_name(), inch.get_type())
38  prev = copy_to_residues(
39  inch,
40  outch,
41  rcf,
42  rf,
43  pcf,
44  pf,
45  acf,
46  af,
47  ccf,
48  cf,
49  bf,
50  prev)
51  return prev
52 fh = RMF.open_rmf_file_read_only(RMF.get_example_path("3U7W.rmf"))
53 fh.set_current_frame(RMF.FrameID(0))
54 
55 outpath = RMF._get_temporary_file_path("3U7W-residues.rmf")
56 out = RMF.create_rmf_file(outpath)
57 out.add_frame("nothing", RMF.FRAME)
58 print("file is", outpath)
59 bf = RMF.BondFactory(out)
60 
61 rcf = RMF.ResidueFactory(fh)
62 rf = RMF.ResidueFactory(out)
63 pcf = RMF.ParticleFactory(fh)
64 pf = RMF.ParticleFactory(out)
65 acf = RMF.AtomFactory(fh)
66 af = RMF.AtomFactory(out)
67 ccf = RMF.ChainFactory(fh)
68 cf = RMF.ChainFactory(out)
69 bf = RMF.BondFactory(out)
70 copy_to_residues(
71  fh.get_root_node(),
72  out.get_root_node(),
73  rcf,
74  rf,
75  pcf,
76  pf,
77  acf,
78  af,
79  ccf,
80  cf,
81  bf,
82  None)
83 
84 RMF.show_hierarchy_with_values(out.get_root_node())
85 RMF.show_hierarchy_with_decorators(out.get_root_node())
void show_hierarchy_with_decorators(NodeConstHandle root, bool verbose=false, std::ostream &out=std::cout)
FileConstHandle open_rmf_file_read_only(std::string path)
FileHandle create_rmf_file(std::string path)
Create an RMF from a file system path.
void show_hierarchy_with_values(NodeConstHandle root)