def create_positions(path, cid, pose): positions = get_new_positions(pose) positions_file = os.path.join( path, "%s_%d.bild" % (DEFAULT_BILD_STARTING_PREFIX, cid)) create_bild_file(positions_file, positions) pos_file_name = os.path.join(path, '%s_%s.dat' % (DEFAULT_STARTING_PREFIX, cid)) create_file_from_poses(pos_file_name, positions)
def test_create_bild_file(self): poses = [[0., 0., 0., 0.5, 0.5, 0.5, 0.5], [2., 2., 2., 0., 0.7071, 0.7071, 0.], [-2., -2., -2., 0., 0., 0.7071, 0.7071]] generated_file = os.path.join(self.test_path, 'test.bild') expected_file = os.path.join(self.golden_data_path, 'test.bild') create_bild_file(generated_file, poses) assert filecmp.cmp(generated_file, expected_file)
def calculate_initial_poses(receptor, ligand, num_clusters, num_glowworms, seed, receptor_restraints, ligand_restraints, rec_translation, lig_translation, dest_folder, ftdock_file='', nm_mode=False, nm_seed=0, rec_nm=0, lig_nm=0, is_membrane=False): """Calculates the starting points for each of the glowworms using the center of swarms""" # Random number generator for poses rng = MTGenerator(seed) # Random number generator for NM if nm_mode: rng_nm = NormalGenerator(nm_seed, mu=DEFAULT_EXTENT_MU, sigma=DEFAULT_EXTENT_SIGMA) else: rng_nm = None # Calculate swarm centers swarm_centers, receptor_diameter, ligand_diameter = calculate_surface_points( receptor, ligand, num_clusters, distance_step=1.0, is_membrane=is_membrane) # Filter swarms far from the restraints if receptor_restraints: regular_restraints = receptor_restraints[ 'active'] + receptor_restraints['passive'] swarm_centers = apply_restraints(swarm_centers, regular_restraints, receptor_restraints['blocked'], ligand_diameter / 2., rec_translation) # Filter out swarms which are not compatible with the explicit membrane if is_membrane: membrane_beads = [ residue for residue in receptor.residues if residue.name == 'MMB' ] swarm_centers = apply_membrane(swarm_centers, membrane_beads, rec_translation) pdb_file_name = os.path.join(dest_folder, CLUSTERS_CENTERS_FILE) create_pdb_from_points(pdb_file_name, swarm_centers) ligand_center = ligand.center_of_coordinates() radius = 10. # ligand_diameter / 2. positions_files = [] # Populate the clusters using the FTDock poses if ftdock_file: if nm_mode: raise NotImplementedError( 'Using FTDock poses with NM is not supported') poses = FTDockCoordinatesParser.get_list_of_poses( ftdock_file, ligand_center) clusters = classify_ftdock_poses(poses, swarm_centers, radius) for cluster_id, ftdock_poses in clusters.items(): # Translate FTDock poses into lightdock poses poses = [] for pose in ftdock_poses: poses.append([ pose.translation[0], pose.translation[1], pose.translation[2], pose.q.w, pose.q.x, pose.q.y, pose.q.z ]) # Populate new poses if needed if len(poses) < num_glowworms: needed = num_glowworms - len(poses) poses.extend( populate_poses(needed, swarm_centers[cluster_id], radius, rng, rec_translation, lig_translation)) # Save poses as pdb file pdb_file_name = os.path.join( dest_folder, '%s_%s.pdb' % (DEFAULT_PDB_STARTING_PREFIX, cluster_id)) create_pdb_from_points(pdb_file_name, [[pose[0], pose[1], pose[2]] for pose in poses[:num_glowworms]]) # Save poses as initial_positions file pos_file_name = os.path.join( dest_folder, '%s_%s.dat' % (DEFAULT_STARTING_PREFIX, cluster_id)) bild_file_name = os.path.join( dest_folder, '%s_%s.bild' % (DEFAULT_BILD_STARTING_PREFIX, cluster_id)) create_file_from_poses(pos_file_name, poses[:num_glowworms]) positions_files.append(pos_file_name) create_bild_file(bild_file_name, poses) else: for swarm_id, swarm_center in enumerate(swarm_centers): poses = populate_poses(num_glowworms, swarm_center, radius, rng, rec_translation, lig_translation, rng_nm, rec_nm, lig_nm, receptor_restraints, ligand_restraints, ligand_diameter) # Save poses as pdb file pdb_file_name = os.path.join( dest_folder, '%s_%s.pdb' % (DEFAULT_PDB_STARTING_PREFIX, swarm_id)) create_pdb_from_points(pdb_file_name, [[pose[0], pose[1], pose[2]] for pose in poses[:num_glowworms]]) # Save poses as initial_positions file pos_file_name = os.path.join( dest_folder, '%s_%s.dat' % (DEFAULT_STARTING_PREFIX, swarm_id)) bild_file_name = os.path.join( dest_folder, '%s_%s.bild' % (DEFAULT_BILD_STARTING_PREFIX, swarm_id)) create_file_from_poses(pos_file_name, poses[:num_glowworms]) positions_files.append(pos_file_name) create_bild_file(bild_file_name, poses) return positions_files
def calculate_initial_poses(receptor, ligand, num_swarms, num_glowworms, seed, receptor_restraints, ligand_restraints, rec_translation, lig_translation, surface_density, dest_folder, nm_mode=False, nm_seed=0, rec_nm=0, lig_nm=0, is_membrane=False, is_transmembrane=False, writing_starting_positions=False, swarm_radius=10.): """Calculates the starting points for each of the glowworms using the center of swarms""" # Random number generator for poses rng = MTGenerator(seed) # Random number generator for NM if nm_mode: rng_nm = NormalGenerator(nm_seed, mu=DEFAULT_EXTENT_MU, sigma=DEFAULT_EXTENT_SIGMA) else: rng_nm = None # Calculate swarm centers has_membrane = is_membrane or is_transmembrane swarm_centers, receptor_diameter, ligand_diameter = calculate_surface_points( receptor, ligand, num_swarms, rec_translation, surface_density, seed=seed, has_membrane=has_membrane) # Filter swarms far from the restraints if receptor_restraints: regular_restraints = receptor_restraints[ 'active'] + receptor_restraints['passive'] swarm_centers = apply_restraints(swarm_centers, regular_restraints, receptor_restraints['blocked'], ligand_diameter / 2., rec_translation) # Filter out swarms which are not compatible with the explicit membrane if has_membrane: membrane_beads = [ residue for residue in receptor.residues if residue.name == 'MMB' ] swarm_centers = apply_membrane(swarm_centers, membrane_beads, rec_translation, is_transmembrane) pdb_file_name = os.path.join(dest_folder, SWARM_CENTERS_FILE) create_pdb_from_points(pdb_file_name, swarm_centers) ligand_center = ligand.center_of_coordinates() positions_files = [] for swarm_id, swarm_center in enumerate(swarm_centers): poses = populate_poses(num_glowworms, swarm_center, swarm_radius, rng, rec_translation, lig_translation, rng_nm, rec_nm, lig_nm, receptor_restraints, ligand_restraints, ligand_diameter) if writing_starting_positions: # Save poses as pdb file pdb_file_name = os.path.join( dest_folder, '%s_%s.pdb' % (DEFAULT_PDB_STARTING_PREFIX, swarm_id)) create_pdb_from_points(pdb_file_name, [[pose[0], pose[1], pose[2]] for pose in poses[:num_glowworms]]) # Generate bild files for glowworm orientations bild_file_name = os.path.join( dest_folder, '%s_%s.bild' % (DEFAULT_BILD_STARTING_PREFIX, swarm_id)) create_bild_file(bild_file_name, poses) # Save poses as initial_positions file pos_file_name = os.path.join( dest_folder, '%s_%s.dat' % (DEFAULT_STARTING_PREFIX, swarm_id)) create_file_from_poses(pos_file_name, poses[:num_glowworms]) positions_files.append(pos_file_name) return positions_files
def create_positions(path, cid, pose): positions = get_new_positions(pose) positions_file = os.path.join(path, "%s_%d.bild" % (DEFAULT_BILD_STARTING_PREFIX, cid)) create_bild_file(positions_file, positions) pos_file_name = os.path.join(path, '%s_%s.dat' % (DEFAULT_STARTING_PREFIX, cid)) create_file_from_poses(pos_file_name, positions)