Opened 7 years ago

Closed 7 years ago

#1275 closed enhancement (fixed)

Get residue's bonded neighbors

Reported by: Tristan Croll Owned by: Eric Pettersen
Priority: moderate Milestone:
Component: Core Version:
Keywords: Cc:
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

Easy enough to implement something for myself, but seems like a function that would be useful in the core. Akin to Atom.neighbors, it would be good to have a Residue.neighbors that returns all residues covalently bonded to the given residue. All that seems to exist at present is a function to test if the residue is connected to a single other user-specified residue.

Change History (3)

comment:1 by Eric Pettersen, 7 years ago

Status: assignedfeedback

So you mean r.atoms.bonds.atoms.unique_residues with 'r' removed? I could easily add that as a property of Residue.

in reply to:  2 ; comment:2 by tic20@…, 7 years ago

More or less, yes (although there is currently no Atoms.bonds on the 
Python side, only Atoms.intra_bonds). The below C++ snippet gets the 
result I was after (and is working for me, so no urgency). The use case 
is where the model contains residues which aren't parameterised for 
molecular dynamics. I want to be able to keep them in the model and just 
exclude them from simulations, but to avoid things going pear-shaped 
this means I have to fix the positions of any atoms directly bonded to 
them.

extern "C" EXPORT PyObject*
residue_bonded_neighbors(void *residue)
{
     Residue *r = static_cast<Residue *>(residue);
     try {
         std::set<Residue *> rset;
         for (auto a: r->atoms())
         {
             auto neighbors = a->neighbors();
             for (auto n: neighbors)
             {
                 if (n->residue() != r)
                     rset.insert(n->residue());
             }
         }
         void **rptr;
         PyObject* ra = python_voidp_array(rset.size(), &rptr);
         for (auto rr: rset)
             *(rptr++) = rr;
         return ra;
     } catch (...) {
         molc_error();
         return 0;
     }
}


On 2018-08-30 18:15, ChimeraX wrote:

comment:3 by Eric Pettersen, 7 years ago

Resolution: fixed
Status: feedbackclosed

Well, it was trickier than I thought (besides no Atoms.bonds, Bonds.atoms returns a 2-tuple of Atoms), but 'neighbors' is now a property of Residue.

--Eric

Note: See TracTickets for help on using tickets.