Ticket #1431: make_pbs.py

File make_pbs.py, 925 bytes (added by Eric Pettersen, 7 years ago)

Added by email2trac

Line 
1from chimerax.atomic import Structure
2atom_lookup = {}
3for m in session.models:
4 if not isinstance(m, Structure):
5 continue
6 chains = atom_lookup.setdefault(m.id_string, {})
7 for chain in m.chains:
8 residues = chains.setdefault(chain.chain_id, {})
9 for r in chain.existing_residues:
10 atoms = residues.setdefault("%d%s" % (r.number, r.insertion_code), {})
11 for a in r.atoms:
12 atoms[a.name] = a
13
14
15def spec_to_atom(spec):
16 model_spec, remainder = spec.split('/')
17 model = atom_lookup[model_spec[1:]]
18 chain_id, remainder = remainder.split(':')
19 chain = model[chain_id]
20 res_id, atom_name = remainder.split('@')
21 residue = chain[res_id]
22 return residue[atom_name]
23
24pbg = session.pb_manager.get_group("custom pseudobonds")
25import sys
26with open(sys.argv[1], "r") as pb_file:
27 for line in pb_file:
28 a1, a2 = [spec_to_atom(spec) for spec in line.strip().split()]
29 pbg.new_pseudobond(a1, a2)
30session.models.add([pbg])
31
32
33
34