# Iterating over graph edges in PyRosetta.

4 posts / 0 new
Iterating over graph edges in PyRosetta.
#1

I would like to get all residues that are close to any chosen residue in my pose. (I need a list of all residues whose side chains could potentially interact with the side chain of my chosen residue.)

I’m guessing the information is available in pose.energies().tenA_neighbor_graph(), but I can’t seem to access it in PyRosetta.

calling:

for l in pose.energies().tenA_neighbor_graph().get_node(1).edge_list_begin():
pass

returns:

TypeError: 'EdgeListIterator' object is not iterable

and the graph::Node does not seem to expose an array or list or linked-list of edges of each node.

Creating a Vector1 (as suggested here) gives the same error.
rosetta.Vector1(pose.energies().tenA_neighbor_graph().get_node(1).edge_list_begin())

Is it possible to iterate over the edges in a node in PyRosetta?

Thank you for your help &  best regards,
Ajasja

Category:
Post Situation:
Mon, 2014-09-22 07:21
ajasja

Is there any reason you want to use the neighbor graph iteration to do this?

Probably the easier way to do it would be to do a double for-loop iteration over the residues in the pose:

for ii in range(1,pose.total_residue()+1):

for jj in range(ii+1,pose.total_residue()+1):

if not is_neighbor(pose, ii, jj):

continue

#Do whatever you want with neighbor residues

You would have to write the is_neighbor() function yourself, but this allows you to more accurately control how you classify neighbor residues. Rosetta uses a definition that's optimized for the particular use case in the energy function definition, but you may prefer a slightly different one.

Mon, 2014-09-22 08:19
rmoretti

I wanted to reuse the existing calculation already performed by PyRosetta. (Also since it’s in C++ it’s probably faster than doing this at the Python side. If this speed difference matters is of course another question.)

Perhaps I will have to “manually” implement neighbourhood detection in the end. Since my next question was how to get a neighbourhood graph at an arbitrary distance not just at 10 or 12 Angstrom :) The custom approach would also enable me to have a separate radius defined for each residue.

I did also find a hacky workaround using  graph.get_edge_exists

def get_close_resids(pose, target_resid):

graph = pose.energies().tenA_neighbor_graph()

resids = []

for r in range(1,graph.num_nodes()+1):

if (r <> target_resid) and graph.get_edge_exists(target_resid, r):

resids.append(r)

return resids

Mon, 2014-09-22 10:02
ajasja

Yeah, the edge_list_begin() returns a C++ iterator, which doesn't mesh well with the Python iterators in for loops. There's not really a way exposed to iterate through the edges on the Python level. The workaround you've come up with is probably the best way to do things if you want to extract the information out of the existing tenA_neighbor_graph.

Tue, 2014-09-23 08:44
rmoretti