99from lightdock .mathutil .lrandom import MTGenerator , NormalGenerator
1010from lightdock .mathutil .cython .quaternion import Quaternion
1111from lightdock .mathutil .cython .cutil import distance as cdistance
12+ from lightdock .mathutil .cython .cutil import norm
1213from lightdock .constants import CLUSTERS_CENTERS_FILE ,\
1314 DEFAULT_PDB_STARTING_PREFIX , DEFAULT_STARTING_PREFIX , DEFAULT_BILD_STARTING_PREFIX , DEFAULT_EXTENT_MU , \
1415 DEFAULT_EXTENT_SIGMA
1516from lightdock .prep .geometry import create_bild_file
17+ from lightdock .structure .residue import Residue
1618
1719
1820def get_random_point_within_sphere (number_generator , radius ):
@@ -100,11 +102,12 @@ def get_quaternion_for_restraint(rec_residue, lig_residue, tx, ty, tz, rt, lt):
100102
101103
102104def populate_poses (to_generate , center , radius , number_generator , rec_translation , lig_translation ,
103- rng_nm = None , rec_nm = 0 , lig_nm = 0 , receptor_restraints = None , ligand_restraints = None ):
105+ rng_nm = None , rec_nm = 0 , lig_nm = 0 , receptor_restraints = None , ligand_restraints = None ,
106+ ligand_diameter = 1. ):
104107 """Creates new poses around a given center and a given radius"""
105108 new_poses = []
106109
107- # Calculate closer residue restraints
110+ # Calculate closest residue restraints
108111 closest_residues = []
109112 if receptor_restraints :
110113 distances = []
@@ -118,24 +121,47 @@ def populate_poses(to_generate, center, radius, number_generator, rec_translatio
118121 closest_residues = [x [0 ] for x in distances [:10 ]]
119122
120123 for _ in xrange (to_generate ):
124+ # First calculate a random translation within the swarm sphere
121125 x , y , z = get_random_point_within_sphere (number_generator , radius )
122126 tx = center [0 ] + x
123127 ty = center [1 ] + y
124128 tz = center [2 ] + z
129+
130+ # Restraints in both partners
125131 if receptor_restraints and ligand_restraints :
132+ # We select one of the closest residue restraints to point the quaternion
126133 rec_residue = receptor_restraints [closest_residues [number_generator .randint (0 , len (closest_residues )- 1 )]]
134+ # Random restraint on the ligand to use for pre-orientation
127135 lig_residue = ligand_restraints [number_generator .randint (0 , len (ligand_restraints )- 1 )]
136+ # Calculate the quaternion which rotates the ligand to point to the given receptor restraint
128137 q = get_quaternion_for_restraint (rec_residue , lig_residue , tx , ty , tz ,
129138 rec_translation , lig_translation )
139+
140+ # Only restraints in the ligand partner
141+ elif ligand_restraints and not receptor_restraints :
142+ # The strategy is similar to previous but for the receptor side we will use a simulated point
143+ # over the receptor surface to point out the quaternion
144+ coef = norm (center ) / ligand_diameter
145+ rec_residue = Residue .dummy (center [0 ]* coef , center [1 ]* coef , center [2 ]* coef )
146+ lig_residue = ligand_restraints [number_generator .randint (0 , len (ligand_restraints )- 1 )]
147+ q = get_quaternion_for_restraint (rec_residue , lig_residue , 0 , 0 , 0 ,
148+ [0 ,0 ,0 ], lig_translation )
149+ # No restraints at all
130150 else :
131151 q = Quaternion .random (number_generator )
152+
153+ # Glowworm's optimization vector
132154 op_vector = [tx , ty , tz , q .w , q .x , q .y , q .z ]
155+
156+ # If ANM is enabled, we need to create random components for the extents
133157 if rng_nm :
134158 if rec_nm > 0 :
135159 op_vector .extend ([rng_nm () for _ in xrange (rec_nm )])
136160 if lig_nm > 0 :
137161 op_vector .extend ([rng_nm () for _ in xrange (lig_nm )])
162+
138163 new_poses .append (op_vector )
164+
139165 return new_poses
140166
141167
@@ -295,7 +321,7 @@ def calculate_initial_poses(receptor, ligand, num_clusters, num_glowworms,
295321 else :
296322 for swarm_id , swarm_center in enumerate (swarm_centers ):
297323 poses = populate_poses (num_glowworms , swarm_center , radius , rng , rec_translation , lig_translation ,
298- rng_nm , rec_nm , lig_nm , receptor_restraints , ligand_restraints )
324+ rng_nm , rec_nm , lig_nm , receptor_restraints , ligand_restraints , ligand_diameter )
299325 # Save poses as pdb file
300326 pdb_file_name = os .path .join (dest_folder , '%s_%s.pdb' % (DEFAULT_PDB_STARTING_PREFIX , swarm_id ))
301327 create_pdb_from_points (pdb_file_name , [[pose [0 ], pose [1 ], pose [2 ]] for pose in poses [:num_glowworms ]])
0 commit comments