def test_calculate_initial_poses(self): file_name = self.golden_data_path / '3p0g' / 'receptor_membrane.pdb' _, _, chains = parse_complex_from_file(file_name) receptor = Complex(chains, structure_file_name=file_name) file_name = self.golden_data_path / '3p0g' / 'ligand.pdb' _, _, chains = parse_complex_from_file(file_name) ligand = Complex(chains, structure_file_name=file_name) rec_translation = receptor.move_to_origin() lig_translation = ligand.move_to_origin() num_swarms = 100 num_glowworms = 10 surface_density = 50. restraints = parse_restraints_file(self.golden_data_path / '3p0g' / 'restraints.list') receptor_restraints = get_restraints(receptor, restraints['receptor']) ligand_restraints = get_restraints(ligand, restraints['ligand']) rec_restraints = receptor_restraints['active'] + receptor_restraints['passive'] lig_restraints = ligand_restraints['active'] + ligand_restraints['passive'] positions_files = calculate_initial_poses(receptor, ligand, num_swarms, num_glowworms, STARTING_POINTS_SEED, rec_restraints, lig_restraints, rec_translation, lig_translation, surface_density, dest_folder=self.test_path, is_membrane=True) assert filecmp.cmp(positions_files[0], self.golden_data_path / '3p0g' / 'init' / 'initial_positions_0.dat') assert filecmp.cmp(positions_files[1], self.golden_data_path / '3p0g' / 'init' / 'initial_positions_1.dat')
def test_blocked_restraints_file(self): input_file = os.path.join(self.golden_data_path, 'rst_4.lst') restraints = parse_restraints_file(input_file) expected = {'receptor': {'active': ['A.ALA.1'], 'passive': [], 'blocked':['A.LYS.2']}, 'ligand': {'active': [], 'passive': ['B.TYR.1'], 'blocked':['B.TRP.2']}} assert restraints == expected
def test_empty_restraints_file(self): input_file = os.path.join(self.golden_data_path, 'rst_3.lst') restraints = parse_restraints_file(input_file) expected = {'receptor': {'active': [], 'passive': [], 'blocked':[]}, 'ligand': {'active': [], 'passive': [], 'blocked':[]}} assert restraints == expected
def test_restraints_file_with_duplicate(self): input_file = os.path.join(self.golden_data_path, 'rst_2.lst') restraints = parse_restraints_file(input_file) expected = { 'receptor': { 'active': ['A.ALA.1'], 'passive': [] }, 'ligand': { 'active': [], 'passive': ['B.TYR.1'] } } assert restraints == expected
def test_calculate_initial_poses(self): atoms, residues, chains = parse_complex_from_file( os.path.join(self.golden_data_path, '3p0g', 'receptor_membrane.pdb')) receptor = Complex(chains) atoms, residues, chains = parse_complex_from_file( os.path.join(self.golden_data_path, '3p0g', 'ligand.pdb')) ligand = Complex(chains) rec_translation = receptor.move_to_origin() lig_translation = ligand.move_to_origin() num_swarms = 10 num_glowworms = 10 seed = 324324 restraints = parse_restraints_file( os.path.join(self.golden_data_path, '3p0g', 'restraints.list')) receptor_restraints = get_restraints(receptor, restraints['receptor']) ligand_restraints = get_restraints(ligand, restraints['ligand']) rec_restraints = receptor_restraints['active'] + receptor_restraints[ 'passive'] lig_restraints = ligand_restraints['active'] + ligand_restraints[ 'passive'] positions_files = calculate_initial_poses(receptor, ligand, num_swarms, num_glowworms, seed, rec_restraints, lig_restraints, rec_translation, lig_translation, dest_folder=self.test_path, is_membrane=True) assert filecmp.cmp( positions_files[0], os.path.join(self.golden_data_path, '3p0g', 'init', 'initial_positions_0.dat')) assert filecmp.cmp( positions_files[1], os.path.join(self.golden_data_path, '3p0g', 'init', 'initial_positions_1.dat'))
def test_simple_restraints_file(self): input_file = self.golden_data_path / 'rst_1.lst' restraints = parse_restraints_file(input_file) expected = { 'receptor': { 'active': ['A.ALA.1'], 'passive': [], 'blocked': [] }, 'ligand': { 'active': [], 'passive': ['B.TYR.1'], 'blocked': [] } } assert restraints == expected
save_lightdock_structure(ligand) # Calculate and save ANM if required if args.use_anm: if args.anm_rec > 0: log.info("Calculating ANM for receptor molecule...") calculate_anm(receptor, args.anm_rec, DEFAULT_REC_NM_FILE) if args.anm_lig > 0: log.info("Calculating ANM for ligand molecule...") calculate_anm(ligand, args.anm_lig, DEFAULT_LIG_NM_FILE) # Parse restraints if any: receptor_restraints = ligand_restraints = None if args.restraints: log.info("Reading restraints from %s" % args.restraints) restraints = parse_restraints_file(args.restraints) # Calculate number of restraints in order to check them num_rec_active = len(restraints['receptor']['active']) num_rec_passive = len(restraints['receptor']['passive']) num_lig_active = len(restraints['ligand']['active']) num_lig_passive = len(restraints['ligand']['passive']) # Check if restraints have been defined for the ligand, but not to the receptor if not num_rec_active and not num_rec_passive and ( num_lig_active or num_lig_passive): raise LightDockError( "Restraints defined for ligand, but not receptor. Try switching structures." ) if not num_rec_active and not num_rec_passive and not num_lig_active and not num_lig_passive:
save_lightdock_structure(ligand) # Calculate and save ANM if required if args.use_anm: if args.anm_rec > 0: log.info("Calculating ANM for receptor molecule...") calculate_anm(receptor, args.anm_rec, DEFAULT_REC_NM_FILE) if args.anm_lig > 0: log.info("Calculating ANM for ligand molecule...") calculate_anm(ligand, args.anm_lig, DEFAULT_LIG_NM_FILE) # Parse restraints if any: receptor_restraints = ligand_restraints = None if args.restraints: log.info("Reading restraints from %s" % args.restraints) restraints = parse_restraints_file(args.restraints) # Calculate number of restraints in order to check them num_rec_active = len(restraints['receptor']['active']) num_rec_passive = len(restraints['receptor']['passive']) num_lig_active = len(restraints['ligand']['active']) num_lig_passive = len(restraints['ligand']['passive']) # Check if restraints have been defined for the ligand, but not to the receptor if not num_rec_active and not num_rec_passive and (num_lig_active or num_lig_passive): raise LightDockError("Restraints defined for ligand, but not receptor. Try switching structures.") if not num_rec_active and not num_rec_passive and not num_lig_active and not num_lig_passive: raise LightDockError("Restraints file specified, but not a single restraint found") # Check if restraints correspond with real residues