Ticket #3425: add_oxt.py

File add_oxt.py, 1.8 KB (added by Tristan Croll, 5 years ago)

Added by email2trac

Line 
1# @Author: Tristan Croll <tic20>
2# @Date: 20-Jun-2020
3# @Email: tic20@cam.ac.uk
4# @Last modified by: tic20
5# @Last modified time: 20-Jun-2020
6# @License: Free for non-commercial use (see license.pdf)
7# @Copyright: 2016-2019 Tristan Croll
8
9from chimerax.atomic import selected_residues, Residue
10from chimerax.core.errors import UserError
11
12def add_oxt(session, residue):
13 catom = residue.find_atom('C')
14 resname = residue.name
15 if catom is None:
16 session.logger.warning('Residue {} {}{} has no C atom!'.format(residue.name, residue.chain_id, residue.number))
17 return
18 color = catom.color
19 for n in catom.neighbors:
20 if n.name=='OXT':
21 session.logger.warning('Chain {} already has a C-terminal OXT. Skipping.')
22 return
23 if n.residue != residue:
24 raise UserError('Residue {} {}{} is not a C-terminal residue!'.format(residue.name, residue.chain_id, residue.number))
25 from chimerax.atomic.build_structure import modify_atom
26 from chimerax.atomic import Element
27 atoms = modify_atom(catom, catom.element, 3, res_name=residue.name)
28 for a in atoms:
29 if a.element.name=='H':
30 break
31 modify_atom(a, Element.get_element('O'), 1, name='OXT', res_name=residue.name)
32 catom.color = color
33 session.logger.info('Added a C-terminal OXT to chain {}'.format(residue.chain_id))
34
35
36sel = selected_residues(session)
37if not len(sel):
38 raise UserError('No atoms selected!')
39sel = sel[sel.polymer_types==Residue.PT_AMINO]
40if not len(sel):
41 raise UserError('No protein selected!')
42us = sel.unique_structures
43if len(us) != 1:
44 raise UserError('Selection must be from a single model!')
45m = sel.unique_structures
46cids = sel.unique_chain_ids
47for cid in cids:
48 chain = m.chains[m.chains.chain_ids==cid][0]
49 last_res = chain.residues[-1]
50 add_oxt(session, last_res)