1 """@namespace IMP.EMageFit.buildxlinks
2 Utility functions to handle cross links.
16 from sets
import Set
as set
18 log = logging.getLogger(
"buildxlinks")
23 Class defining a cross-link
26 def __init__(self, id1, chain1, residue1,
27 id2, chain2, residue2,
31 @param[in] id1 Id of the first component of the cross-link
32 @param[in] chain1 Chain of the first component
33 @param[in] residue1 Residue cross-linked in the first component
34 @param[in] id2 Id of the second component of the cross-link
35 @param[in] chain2 chain1 Chain of the second component
36 @param[in] residue2 Residue cross-linked in the second component
37 @param[in] distance Maximum distance
40 self.first_chain = chain1
41 self.first_residue = residue1
43 self.second_chain = chain2
44 self.second_residue = residue2
45 self.distance = distance
48 xl =
Xlink(self.first_id, self.first_chain, self.first_residue,
49 self.second_id, self.second_chain, self.second_residue,
53 def __eq__(self, other):
54 if self.first_id != other.first_id
or \
55 self.second_id != other.second_id
or \
56 self.first_chain != other.first_chain
or \
57 self.second_chain != other.second_chain
or \
58 self.first_residue != other.first_residue
or \
59 self.second_residue != other.second_residue
or \
60 abs(other.distance - self.distance) > 0.01:
66 swaps the order of the residues in the restraint
68 self.first_id, self.second_id = self.second_id, self.first_id
69 self.first_residue, self.second_residue = \
70 self.second_residue, self.first_residue
71 self.first_chain, self.second_chain = \
72 self.second_chain, self.first_chain
75 s =
"Cross Link: %s %s %d - %s %s %d. Distance %f" % (
76 self.first_id, self.first_chain, self.first_residue,
77 self.second_id, self.second_chain, self.second_residue,
83 Generate a unique name for the restraint.
84 @note: The name cannot start with a number, upsets sqlite
86 name =
"cl_%s_%s%d_%s_%s%d" % (self.first_id, self.first_chain,
87 self.first_residue, self.second_id,
88 self.second_chain, self.second_residue)
94 Build a set of nodes and edges from the set of crosslinking
96 @param xlinks_dict a XlinksDict class
101 for key
in xlinks_dict.keys():
104 edge = sorted([key[0], key[1]])
105 if edge
not in edges:
107 log.debug(
"Subunits %s", subunits)
108 log.debug(
"Edges %s", edges)
109 return subunits, edges
115 Description of crosslinking restraints as a python
117 The keys are a pair with the ids of the cross-linked subunits.
118 Note: The pairs are considered in alphabetic order
123 Add a xlink. It is ensured that the id of the first element is
124 is lower that the second
126 if xlink.second_id < xlink.first_id:
128 key = (xlink.first_id, xlink.second_id)
129 if key
not in self.keys():
131 self[key].append(xlink)
135 @param pair_ids Ids fo the subunits that are cross-linked
138 xlinks_list = self[pair_ids]
139 ys = [xl.clone()
for xl
in xlinks_list]
143 xlinks_list = self[(pair_ids[1], pair_ids[0])]
144 ys = [xl.clone()
for xl
in xlinks_list]
149 except KeyError
as e:
155 return self[pair_ids]
157 print pair_ids,"NOT FOUND, swapping to",(pair_ids[1], pair_ids[0])
158 # If not found, invert the pair
159 xlinks_list = self[(pair_ids[1], pair_ids[0])]
160 # swap the xlinks, so the first element of the pair corresponds
161 # to the first id in the xlink
162 for xl in xlinks_list:
164 for xl in xlinks_list:
173 Compute the order of the docking experiments. The order is derived
174 from the cross-linking restraints:
175 1) The subunit with the highest number of cross-links with others
176 works as the first receptor (A)
177 2) All the subunits cross-linked with A are docked into A.
178 3) The next receptor (B) is the subunit that has the highest number of
180 4) All the subunits cross-linked to B are docked into B (except A)
181 5) The procedure is repeated until there are no more cross-links
189 Instead of setting the xlink restraints, init the graph directly
190 Example of what to pass with the structure in 3sfd
191 G.add_nodes_from(["A", "B", "C", "D"])
192 G.add_edges_from([("B","C"), ("B","A"), ("B","D"), ("C","D")])
193 ("B","C") means that there are cross-links between B and C
195 self.G.add_nodes_from(subunits)
196 self.G.add_edges_from(edges)
200 Sets the xlinks used for computing the docking order
201 @param xlinks_dict XlinksDict class
207 """ return the order to dock components from the cross links """
209 degs = self.G.degree(self.G.nodes())
210 log.debug(
"Degrees: %s", degs)
211 sorted_degrees = sorted(((v, k)
for (k, v)
in dict(degs).items()),
214 receptors_considered = []
215 for degree, node
in sorted_degrees:
216 for n
in self.G.neighbors(node):
217 if n
not in receptors_considered:
218 docking_pairs.append((node, n))
219 receptors_considered.append(node)
220 log.info(
"The suggested order for the docking pairs is %s",
228 Puts two subunits together using the Xlinkins restraints. The solutions
229 offered by this class are just an initial position of the components
233 def clear_xlinks(self):
234 self.xlinks_list = []
238 Sets the xlinks used for the computation fo the initial rough
240 @param xlinks_list A list of Xlink classes
241 residue1 belongs to the receptor and residue2 belongs to the ligand
243 self.xlinks_list = xlinks_list
247 Set the name of the PDB files of the receptor and the ligand
253 self.h_receptor = atom.read_pdb(fn_receptor, self.m_receptor, sel)
255 self.h_ligand = atom.read_pdb(fn_ligand, self.m_ligand, sel)
259 Set the hierarchies (atom.Hierarchy objects) for the receptor and
264 self.h_receptor = h_receptor
265 self.h_ligand = h_ligand
269 Sets the rigid bodies (core.RigidBody objects) for the receptor and
274 self.rb_receptor = rb_receptor
275 self.rb_ligand = rb_ligand
279 Movest the ligand close to the receptor based on the xlinks
280 provided by set_xlinks()
282 log.debug(
"Moving ligand close to the receptor using the xlinks")
283 n = len(self.xlinks_list)
291 Get the particle representing a residue in a hierarchy
292 @param h atom.Hierarchy containing the residue
293 @param ch The chain id
294 @param res index of the residue
297 return s.get_selected_particles()[0]
301 Get the coordinates for a residue in a molecular hierarchy
302 @param h atom.Hierarchy object
303 @param ch The chain id
304 @param res Residue index
307 return core.XYZ(p).get_coordinates()
311 Write a pdb file the coordinates of the ligand
314 atom.write_pdb(self.h_ligand, fn)
318 Put the residues in a random distance between 0 and the maximum
319 cross-linkin distance
321 xl = self.xlinks_list[0]
324 sph = alg.Sphere3D(center, xl.distance)
325 v = alg.get_random_vector_in(sph)
326 ref = self.rb_ligand.get_reference_frame()
327 coords = ref.get_transformation_to().get_translation()
328 R = ref.get_transformation_to().get_rotation()
331 log.debug(
"Ligand residue before moving %s", lig)
332 displacement = v - lig
333 T = alg.Transformation3D(R, coords + displacement)
334 self.rb_ligand.set_reference_frame(alg.ReferenceFrame3D(T))
336 self.h_ligand, xl.second_chain,
338 log.debug(
"ligand after moving %s", new_coords)
342 Function equivalent to move_one_xlink() for the case where there
343 are more than one cross-link restraints available.
344 Puts the ligand residues as close as possible to the receptor
349 for xl
in self.xlinks_list:
356 log.debug(
"Receptor residues before moving %s", rec_coords)
357 log.debug(
"Ligand residues before moving %s", lig_coords)
358 ref = self.rb_ligand.get_reference_frame()
359 Tr = alg.get_transformation_aligning_first_to_second(lig_coords,
361 T = ref.get_transformation_to()
362 newT = alg.compose(Tr, T)
363 self.rb_ligand.set_reference_frame(alg.ReferenceFrame3D(newT))
365 moved_lig_coords = []
366 for xl
in self.xlinks_list:
369 moved_lig_coords.append(c)
370 log.debug(
"Ligand residues after moving %s", moved_lig_coords)
def write_ligand
Write a pdb file the coordinates of the ligand.
def move_ligand
Movest the ligand close to the receptor based on the xlinks provided by set_xlinks() ...
def set_pdbs
Set the name of the PDB files of the receptor and the ligand.
Class defining a cross-link.
def get_name
Generate a unique name for the restraint.
Class for storing model, its restraints, constraints, and particles.
Select all non-alternative ATOM records.
def set_xlinks
Sets the xlinks used for the computation fo the initial rough docking solution.
def set_xlinks
Sets the xlinks used for computing the docking order.
Compute the order of the docking experiments.
def build_xlinks_graph
Build a set of nodes and edges from the set of crosslinking restraints.
def __init__
Initialize the class.
A decorator for a particle with x,y,z coordinates.
def get_residue_particle
Get the particle representing a residue in a hierarchy.
def get_docking_order
return the order to dock components from the cross links
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
Description of crosslinking restraints as a python dictionary.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
def swap
swaps the order of the residues in the restraint
def set_components_and_connections
Instead of setting the xlink restraints, init the graph directly Example of what to pass with the str...
def move_one_xlink
Put the residues in a random distance between 0 and the maximum cross-linkin distance.
def set_rigid_bodies
Sets the rigid bodies (core.RigidBody objects) for the receptor and the ligand.
Functionality for loading, creating, manipulating and scoring atomic structures.
def get_residue_coordinates
Get the coordinates for a residue in a molecular hierarchy.
Select hierarchy particles identified by the biological name.
def set_hierarchies
Set the hierarchies (atom.Hierarchy objects) for the receptor and the ligand.
Puts two subunits together using the Xlinkins restraints.
def move_xlinks
Function equivalent to move_one_xlink() for the case where there are more than one cross-link restrai...