| 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 |
|
|---|
| 9 | from chimerax.atomic import selected_residues, Residue
|
|---|
| 10 | from chimerax.core.errors import UserError
|
|---|
| 11 |
|
|---|
| 12 | def 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 |
|
|---|
| 36 | sel = selected_residues(session)
|
|---|
| 37 | if not len(sel):
|
|---|
| 38 | raise UserError('No atoms selected!')
|
|---|
| 39 | sel = sel[sel.polymer_types==Residue.PT_AMINO]
|
|---|
| 40 | if not len(sel):
|
|---|
| 41 | raise UserError('No protein selected!')
|
|---|
| 42 | us = sel.unique_structures
|
|---|
| 43 | if len(us) != 1:
|
|---|
| 44 | raise UserError('Selection must be from a single model!')
|
|---|
| 45 | m = sel.unique_structures
|
|---|
| 46 | cids = sel.unique_chain_ids
|
|---|
| 47 | for 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)
|
|---|