| 1 | from chimerax.atomic import Structure
|
|---|
| 2 | atom_lookup = {}
|
|---|
| 3 | for 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 |
|
|---|
| 15 | def 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 |
|
|---|
| 24 | pbg = session.pb_manager.get_group("custom pseudobonds")
|
|---|
| 25 | import sys
|
|---|
| 26 | with 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)
|
|---|
| 30 | session.models.add([pbg])
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|