| 1 | #!/usr/bin/env python3
|
|---|
| 2 | # -*- coding: utf-8 -*-
|
|---|
| 3 | """
|
|---|
| 4 | Created on Thu Dec 3 11:17:08 2020
|
|---|
| 5 |
|
|---|
| 6 | .. codeauthor:: Daniel Esteban Palma Igor <daniel.palma.i@ug.uchile.cl>
|
|---|
| 7 | """
|
|---|
| 8 |
|
|---|
| 9 | from chimerax.core.commands import run
|
|---|
| 10 | from chimerax.atomic.struct_edit import add_atom
|
|---|
| 11 |
|
|---|
| 12 | # if num_atoms == 1, the atom is added to the original Chain,
|
|---|
| 13 | # but if num_atoms >= 2 a new Chain is created
|
|---|
| 14 | num_atoms = 2
|
|---|
| 15 |
|
|---|
| 16 | def print_chains(info, structure):
|
|---|
| 17 | for chain in structure.chains:
|
|---|
| 18 | info(str(chain))
|
|---|
| 19 | for residue in chain.existing_residues[-5:]:
|
|---|
| 20 | info(str(residue))
|
|---|
| 21 | info("")
|
|---|
| 22 |
|
|---|
| 23 | def filter_backbone(atoms):
|
|---|
| 24 | return atoms.filter(atoms.is_backbones())
|
|---|
| 25 |
|
|---|
| 26 | info = session.logger.info
|
|---|
| 27 | structure = run(session, "open 2efv")[0][0]
|
|---|
| 28 | info(f"num_atoms: {num_atoms}")
|
|---|
| 29 | info("Before adding atoms:")
|
|---|
| 30 | print_chains(info, structure) # print
|
|---|
| 31 | sel_atoms = filter_backbone(structure.atoms)
|
|---|
| 32 | last_atom = sel_atoms[-1]
|
|---|
| 33 | i = last_atom.residue.number + 1
|
|---|
| 34 | pbgroup = structure.pseudobond_group("missing structure")
|
|---|
| 35 | chain_id = last_atom.residue.chain_id
|
|---|
| 36 | for _ in range(num_atoms):
|
|---|
| 37 | res = structure.new_residue("UNK", chain_id, i)
|
|---|
| 38 | new_atom = add_atom("CA", "C", res, last_atom.coord - 4)
|
|---|
| 39 | pbgroup.new_pseudobond(last_atom, new_atom)
|
|---|
| 40 | last_atom = new_atom
|
|---|
| 41 | i += 1
|
|---|
| 42 | info("After adding atoms:")
|
|---|
| 43 | print_chains(info, structure) # print
|
|---|