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