def test_zinc_finger(tmp_path): gmx.show_log() ################################## # ## Create the topologie: ### ################################## prot = gmx.GmxSys(name='1jd4', coor_file=PDB_1JD4) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_DIAP1'), vsite='hydrogens', ignore_ZN=False) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 3292 prot.switch_ion_octa_dummy() top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 3304 prot.solvate_add_ions(out_folder=os.path.join(tmp_path, 'top_sys'), maxwarn=3) prot.em(out_folder=os.path.join(tmp_path, 'em_DIAP1'), nsteps=10, constraints='none') em_coor = pdb_manip.Coor(prot.coor_file) assert em_coor.num == 56366 ener_pd = prot.get_ener(['Potential']) assert ener_pd['Potential'].values[-1] < -155000
def test_cys_bond_charmm(tmp_path): gmx.show_log() ################################## # ## Create the topologie: ### ################################## prot = gmx.GmxSys(name='1dpx', coor_file=PDB_1DPX) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_DISU'), vsite='hydrogens', ignore_ZN=False) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 2096 prot.solvate_add_ions(out_folder=os.path.join(tmp_path, 'top_sys'), maxwarn=3) prot.em(out_folder=os.path.join(tmp_path, 'em_DISU'), nsteps=10, constraints='none') em_coor = pdb_manip.Coor(prot.coor_file) assert em_coor.num == 27086 cystein_s_index = em_coor.get_index_selection({ 'name': ['SG'], 'res_name': ['CYS'] }) distance = pdb_manip.Coor.atom_dist(em_coor.atom_dict[cystein_s_index[0]], em_coor.atom_dict[cystein_s_index[-1]]) assert distance < 2.1
def test_insert_ethanol(tmp_path): gmx.show_log() ################################## # ## Create the topologie: ### ################################## prot = gmx.GmxSys(name='1y0m', coor_file=PDB_1Y0M) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_SH3')) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 996 prot.solvate_add_ions(out_folder=os.path.join(tmp_path, 'top_sys')) prot.em(out_folder=os.path.join(tmp_path, 'em_SH3'), nsteps=10, constraints='none') em_coor = pdb_manip.Coor(prot.coor_file) assert em_coor.num == 15383 ener_pd = prot.get_ener(['Potential']) assert ener_pd['Potential'].values[-1] < -155000 ################################### # ### Create Ethanol system ### ################################### smile = 'CCO' eth_pdb = os.path.join(tmp_path, 'ethanol.pdb') charge = ambertools.smile_to_pdb(smile, eth_pdb, 'ETH') assert charge == 0 eth_sys = gmx.GmxSys(name='ETH', coor_file=eth_pdb) eth_sys.prepare_top_ligand(out_folder=os.path.join(tmp_path, 'eth_top'), ff='amber99sb-ildn', include_mol={'ETH': smile}) eth_sys.create_box(name=None, dist=0.5) #################################################### # # Insert 4 copy of ethanol in the SH3 system: ### #################################################### prot.insert_mol_sys(mol_gromacs=eth_sys, mol_num=10, new_name='SH3_ETH', out_folder=os.path.join(tmp_path, 'top_ETH_SH3')) ################################ # ## Minimize the system ### ################################ prot.em_2_steps(out_folder=os.path.join(tmp_path, 'em_ETH_SH3'), no_constr_nsteps=10, constr_nsteps=10) prot_lig_coor = pdb_manip.Coor(prot.coor_file) assert 15300 < prot_lig_coor.num < 15518 prot.display_history()
def test_insert_peptide_vsite(tmp_path): gmx.show_log() ################################## # ## Create the topologie: ### ################################## prot = gmx.GmxSys(name='1y0m', coor_file=PDB_1Y0M) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_SH3'), vsite='hydrogens') top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 1064 prot.solvate_add_ions(out_folder=os.path.join(tmp_path, 'top_sys')) prot.em(out_folder=os.path.join(tmp_path, 'em_SH3'), nsteps=10, constraints='none') em_coor = pdb_manip.Coor(prot.coor_file) assert em_coor.num == 15337 ener_pd = prot.get_ener(['Potential']) assert ener_pd['Potential'].values[-1] < -155000 ################################### # ## Create a DD peptide ### ################################### pep = gmx.GmxSys(name='DD') pep.create_peptide(sequence='DD', out_folder=os.path.join(tmp_path, 'top_DD'), em_nsteps=10, equi_nsteps=0, vsite='hydrogens') #################################################### # # Insert 4 copy of ethanol in the SH3 system: ### #################################################### prot.insert_mol_sys(mol_gromacs=pep, mol_num=10, new_name='SH3_DD', out_folder=os.path.join(tmp_path, 'top_DD_SH3')) ################################ # ## Minimize the system ### ################################ prot.em_2_steps(out_folder=os.path.join(tmp_path, 'em_DD_SH3'), no_constr_nsteps=10, constr_nsteps=10) prot_lig_coor = pdb_manip.Coor(prot.coor_file) assert 15300 < prot_lig_coor.num < 15518 prot.display_history()
def make_amber_top_mol_rdkit(pdb_in, res_name, smile, charge_model="bcc", atom_type="gaff", remove_h=True): full_coor = pdb_manip.Coor(pdb_in) # Select coor: mol_coor = full_coor.select_part_dict(selec_dict={'res_name': [res_name]}) # Change first residue to 1, as it is the res from rdkit output res_list = mol_coor.get_attribute_selection(attribute='res_num') index_list = mol_coor.get_index_selection( selec_dict={'res_num': [res_list[0]]}) mol_coor.change_index_pdb_field(index_list, change_dict={'res_num': 1}) # Remove hydrogens: if remove_h: to_del_list = [] for atom_num, atom in mol_coor.atom_dict.items(): if atom['name'].startswith('H'): to_del_list.append(atom_num) mol_coor.del_atom_index(to_del_list) mol_coor.write_pdb(res_name + '.pdb', check_file_out=False) # Add hydrogens: # add_hydrogen(res_name+'.pdb', res_name+'_h.pdb') charge = add_hydrogen_rdkit(res_name + '.pdb', smile, res_name + '_h.pdb') # Get only one molecule mol_h_coor = pdb_manip.Coor(res_name + '_h.pdb') res_list = mol_h_coor.get_attribute_selection(attribute='uniq_resid') mol_uniq_coor = mol_h_coor.select_part_dict( selec_dict={'uniq_resid': [res_list[0]]}) # Save coordinates: mol_uniq_coor.write_pdb(res_name + '_h_unique.pdb', check_file_out=False) # Compute topologie with acpype: gmxsys = acpype(res_name + '_h_unique.pdb', res_name, net_charge=charge, charge_model="bcc", atom_type="gaff") return ({ 'GmxSys': gmxsys, 'coor': os_command.full_path_and_check(res_name + '_h.pdb'), 'num': len(res_list) })
def test_solv_water_free(tmp_path): mol_free = FreeEner('DEN', f'{tmp_path}/indene_water_solv') mol_free.water_box_from_SMILE('C1C=Cc2ccccc12') start_coor = pdb_manip.Coor(mol_free.gmxsys.coor_file) assert start_coor.num == 1625 # To avoid domain decomposition errors: # Use only one proc mol_free.gmxsys.nt = 1 mol_free.equilibrate_solvent_box(em_steps=100, dt=0.002, prod_time=0.02, short_steps=500) delta_coul = 0.5 coul_list = np.arange(0, 1 + delta_coul, delta_coul) vdw_coul = 0.5 vdw_list = np.arange(0, 1 + vdw_coul, vdw_coul) mol_free.run(lambda_coul_list=coul_list, lambda_vdw_list=vdw_list, em_steps=100, nvt_time=0.1, npt_time=0.1, prod_time=0.1, temp_groups='System') dg_solv, dg_std_solv = mol_free.get_free_ener() print(dg_solv, dg_std_solv) assert ((10 < dg_solv) and (dg_solv < 30))
def test_plot_3D(tmp_path): """ Test plot_pseudo_3D with chains. """ prot_coor = pdb_manip.Coor(PDB_1JD4) plot_chain = prot_coor.plot_pseudo_3D('chain') plot_properties = plot_chain.properties() assert plot_properties['color'].shape == (191, 4) assert len(plot_properties['segments']) == 191 np.testing.assert_allclose(plot_properties['color'][0], [0.66666667, 0., 0.10666667, 1.], rtol=1e-06) np.testing.assert_allclose(plot_properties['color'][-1], [1., 0.33333333, 0.83333333, 1.], rtol=1e-06) plot_beta = prot_coor.plot_pseudo_3D('beta') plot_properties = plot_beta.properties() assert plot_properties['color'].shape == (191, 4) assert len(plot_properties['segments']) == 191 np.testing.assert_allclose(plot_properties['color'][0], [0., 0.666667, 0.576288, 1.], rtol=1e-06) np.testing.assert_allclose(plot_properties['color'][-1], [0.333333, 0.650895, 1., 1.], rtol=1e-05)
def test_set_protonate_amber(tmp_path): gmx.show_log() ########################################## # ## Create the topologie at PH 4.0 ### ########################################## res_prot_dict = { 'GLH': { 'res_num': [9, 24, 31, 57] }, 'ASH': { 'res_num': [3, 70] }, 'HIP': { 'res_num': [28, 35] }, 'HID': { 'res_num': [175] }, 'HIE': { 'res_num': [214] } } prot = gmx.GmxSys(name='1RXZ_ph4', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph4'), ph=7.0, res_prot_dict=res_prot_dict, ff="amber99sb-ildn") top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4081 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == -4
def smile_to_pdb(smile, pdb_out, mol_name, method_3d='rdkit', iter_num=5000): """ """ if method_3d == 'openbabel': from openbabel import pybel conf = pybel.readstring("smi", smile) # Get charge charge = conf.charge conf.make3D(forcefield='mmff94', steps=iter_num) conf.write(format='pdb', filename=pdb_out, overwrite=True) elif method_3d == 'rdkit': from rdkit.Chem import AllChem as Chem conf = Chem.MolFromSmiles(smile) conf = Chem.AddHs(conf) # Get charge charge = Chem.GetFormalCharge(conf) Chem.EmbedMolecule(conf) Chem.MMFFOptimizeMolecule(conf, mmffVariant='MMFF94', maxIters=iter_num) Chem.MolToPDBFile(conf, filename=pdb_out) # Change resname of pdb file to `self.mol_name` coor = pdb_manip.Coor(pdb_out) index_list = coor.get_index_selection(selec_dict={'res_name': ['UNL']}) coor.change_index_pdb_field(index_list, change_dict={'res_name': mol_name}) coor.write_pdb(pdb_out, check_file_out=False) return (charge)
def test_protonate_ph4_7_amber(tmp_path): gmx.show_log() ########################################## # ## Create the topologie at PH 4.0 ### ########################################## prot = gmx.GmxSys(name='1RXZ_ph4', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph4'), ph=4.0, ff="amber99sb-ildn") top_coor = pdb_manip.Coor(prot.coor_file) top_1RXZ = gmx.TopSys(prot.top_file) if (version.parse(pdb2pqr.__version__) < version.parse("3.5")): assert top_coor.num == 4107 assert top_1RXZ.charge() == 22 else: assert top_coor.num == 4106 assert top_1RXZ.charge() == 21 ########################################## # ## Create the topologie at PH 7.0 ### ########################################## prot = gmx.GmxSys(name='1RXZ_ph7', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph7'), ph=7.0, ff="amber99sb-ildn") top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4073 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == -12 ########################################## # ## Create the topologie at PH 10.0 ### ########################################## # Remark: Amber allow lysine unprotonated prot = gmx.GmxSys(name='1RXZ_ph10', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph10'), ph=10.0, ff="amber99sb-ildn") top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4071 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == -14
def test_insert_peptide_vsite(tmp_path): # Gromacs verions >= 2021 support cyclic peptides gmx.show_log() cyclic_pep = gmx.GmxSys(name='5vav', coor_file=PDB_5VAV) top_coor = pdb_manip.Multi_Coor(cyclic_pep.coor_file) assert top_coor.coor_list[0].num == 209 cyclic_pep.cyclic_peptide_top( out_folder=os.path.join(tmp_path, 'cyclic/top')) top_coor = pdb_manip.Coor(cyclic_pep.coor_file) assert top_coor.num == 209 cyclic_top = gmx.TopSys(cyclic_pep.top_file) assert cyclic_top.prot_res_num() == 14 cyclic_top.display() cyclic_pep.em(out_folder=os.path.join(tmp_path, 'cyclic/em/'), nsteps=10, create_box_flag=True) cyclic_amber_pep = gmx.GmxSys(name='5vav_amber', coor_file=PDB_5VAV) top_coor = pdb_manip.Coor(cyclic_pep.coor_file) assert top_coor.num == 209 cyclic_amber_pep.cyclic_peptide_top(out_folder=os.path.join( tmp_path, 'cyclic/top'), ff='amber99sb-ildn') top_coor = pdb_manip.Coor(cyclic_pep.coor_file) assert top_coor.num == 209 cyclic_amber_top = gmx.TopSys(cyclic_amber_pep.top_file) print(cyclic_amber_top.charge()) cyclic_amber_pep.em(out_folder=os.path.join(tmp_path, 'cyclic/em/'), nsteps=10, create_box_flag=True)
def test_smina_rigid(tmp_path, capsys): # Convert to str to avoid problem with python 3.5 TEST_OUT = str(tmp_path) # Redirect pdb_manip logs pdb_manip.show_log() # Extract center and max_sizer: lig_coor = pdb_manip.Coor(os.path.join(TEST_PATH, 'lig.pdbqt')) center_lig = lig_coor.center_of_mass() max_size = lig_coor.get_max_size() print("Center coordinates is {:.1f} {:.1f} {:.1f}, maximum dimension" " is {:.1f} Å".format(*center_lig, max_size)) captured = capsys.readouterr() assert bool(re.match('Succeed to read file .+/input/lig.pdbqt , 50 ' 'atoms found\nDo a rotation of 99.71°\nCenter ' 'coordinates is 13.1 22.5 5.5, maximum dimension is ' '18.0 Å\n', captured.out)) # Create Docking object test_dock = docking.Docking( name='test_smina', rec_pdbqt=os.path.join(TEST_PATH, 'rec.pdbqt'), lig_pdbqt=os.path.join(TEST_PATH, 'lig.pdbqt')) out_dock = os.path.join(TEST_OUT, '{}_dock.pdb'.format('test_smina')) test_dock.run_docking(out_dock, num_modes=10, energy_range=1, exhaustiveness=2, dock_bin='smina', center=center_lig, grid_npts=[max_size + 5] * 3, seed=1) captured = capsys.readouterr() capture_line = captured.out.split('\n') assert bool(re.match( ("smina --ligand .+lig.pdbqt --receptor .+rec.pdbqt --log " ".+test_smina_dock_log.txt --num_modes 10 --exhaustiveness 2" " --energy_range 1 --out .+test_smina_dock.pdb " "--size_x 23.00 --size_y 23.00 --size_z 23.00" " --center_x 13.08 --center_y 22.52 --center_z 5.54" " --seed 1"), capture_line[0])) rmsd_list = test_dock.compute_dock_rmsd(test_dock.lig_pdbqt) assert len(rmsd_list) >= 1 assert rmsd_list[0] < 15 assert len(test_dock.affinity) >= 1 assert test_dock.affinity[1]['affinity'] < -10
def make_amber_top_mol(pdb_in, res_name, charge, charge_model="bcc", atom_type="gaff", remove_h=True): full_coor = pdb_manip.Coor(pdb_in) # Select coor: mol_coor = full_coor.select_part_dict(selec_dict={'res_name': [res_name]}) # Remove hydrogens: if remove_h: to_del_list = [] for atom_num, atom in mol_coor.atom_dict.items(): if atom['name'][0] == 'H': to_del_list.append(atom_num) mol_coor.del_atom_index(to_del_list) mol_coor.write_pdb(res_name + '.pdb') # Add hydrogens: add_hydrogen(res_name + '.pdb', res_name + '_h.pdb') # Get only one molecule mol_h_coor = pdb_manip.Coor(res_name + '_h.pdb') res_list = mol_h_coor.get_attribute_selection(attribute='uniq_resid') mol_uniq_coor = mol_h_coor.select_part_dict( selec_dict={'uniq_resid': [res_list[0]]}) # Save coordinates: mol_uniq_coor.write_pdb(res_name + '_h_unique.pdb') # Compute topologie with acpype: gmxsys = acpype(res_name + '_h_unique.pdb', res_name, net_charge=charge, charge_model="bcc", atom_type="gaff") return ({ 'GmxSys': gmxsys, 'coor': os_command.full_path_and_check(res_name + '_h.pdb'), 'num': len(res_list) })
def test_solv_oct(tmp_path): mol_free = FreeEner('DEN', f'{tmp_path}/indene_oct_solv') mol_free.octanol_box_from_SMILE('C1C=Cc2ccccc12') start_coor = pdb_manip.Coor(mol_free.gmxsys.coor_file) assert start_coor.num == 1502 mol_free.gmxsys.nt = 1 mol_free.equilibrate_solvent_box(em_steps=100, dt=0.002, prod_time=0.02, short_steps=500)
def test_protonate_ph4_7_12_charmm(tmp_path): gmx.show_log() ########################################## # ## Create the topologie at PH 4.0 ### ########################################## prot = gmx.GmxSys(name='1RXZ_ph4', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph4'), ph=4.0) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4108 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == 23 ########################################## # ## Create the topologie at PH 7.0 ### ########################################## prot = gmx.GmxSys(name='1RXZ_ph7', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph7'), ph=7.0) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4073 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == -12 ########################################## # ## Create the topologie at PH 10.0 ### ########################################## # Remark: Charmm doesn't allow lysine unprotonated prot = gmx.GmxSys(name='1RXZ_ph10', coor_file=PDB_1RXZ) prot.prepare_top(out_folder=os.path.join(tmp_path, 'top_1RXZ_ph10'), ph=10.0) top_coor = pdb_manip.Coor(prot.coor_file) assert top_coor.num == 4073 top_1RXZ = gmx.TopSys(prot.top_file) assert top_1RXZ.charge() == -12
def test_pdb2pqr_dna(tmp_path): """ Check that pdb2pqr produce something with dna """ ff = "CHARMM" pdb_manip.show_log() ########################################## # ## Compute protonation at PH 4.0 ### ########################################## out_file = os.path.join(tmp_path, '1D30_charmm_ph4.pqr') pdb2pqr.compute_pdb2pqr(os.path.join(PDB_1D30), out_file, ff=ff, ph=4.0) prot_coor = pdb_manip.Coor(out_file) assert prot_coor.num == 486
def test_free_bind(tmp_path): dna_free = FreeEner('DAP', f'{tmp_path}/1D30_solv') dna_free.prepare_complex_pdb(PDB_1D30, 'NC(=N)c1ccc(cc1)c2[nH]c3cc(ccc3c2)C(N)=N') start_coor = pdb_manip.Coor(dna_free.gmxsys.coor_file) assert start_coor.num == 20973 dna_free.equilibrate_complex(em_steps=100, HA_time=0.001, CA_time=0.002, CA_LOW_time=0.02, dt=0.002, dt_HA=0.001, temp=300, receptor_grp='DNA', short_steps=500) dna_free.compute_add_intermol_from_traj(ref_coor=None, rec_group='DNA') dg_rest_water = dna_free.get_water_restr() print(dg_rest_water) assert ((5.5 < dg_rest_water) and (dg_rest_water < 9.5)) dna_free.plot_intermol_restr() delta_restr = 0.5 restr_list = np.arange(0, 1 + delta_restr, delta_restr) delta_coul = 0.5 coul_list = np.arange(0, 1 + delta_coul, delta_coul) vdw_coul = 0.5 vdw_list = np.arange(0, 1 + vdw_coul, vdw_coul) dna_free.run(lambda_restr_list=restr_list, lambda_coul_list=coul_list, lambda_vdw_list=vdw_list, em_steps=50, nvt_time=0.05, npt_time=0.05, prod_time=0.25, temp_groups='System') dna_free.extend_lambda_prod(prod_time=0.5) dg_bind, dg_std_bind = dna_free.get_free_ener() print(dg_bind, dg_std_bind) assert ((0 < dg_bind) and (dg_bind < 200)) # Need to think about using alchemlyb as a dependance or not dna_free.plot_convergence(dt=0.25, graph_out=f'{tmp_path}/alchem.png') dna_free.compute_convergence_gbar(dt=0.25) dna_free.plot_convergence_graph(graph_out=f'{tmp_path}/bar.png')
def add_hydrogen_rdkit(pdb_in, smile, pdb_out): """Add hydrogen to a pdb file using the ``rdkit`` library: :param pdb_in: pdb input :type pdb_in: str :param pdb_out: pdb output :type pdb_out: str :Example: >>> from pdb_manip_py import pdb_manip >>> pdb_manip.show_log() >>> TEST_OUT = getfixture('tmpdir') >>> # print(TEST_OUT) >>> add_hydrogen_rdkit(pdb_in=os.path.join(TEST_PATH,'four_phenol.pdb'),\ smile="C1=CC=C(C=C1)O",\ pdb_out=os.path.join(TEST_OUT,'four_phenol_h.pdb')) #doctest: +ELLIPSIS Succeed to read file ...four_phenol.pdb , 28 atoms found Succeed to save file ...four_phenol_0.pdb Succeed to read file ...four_phenol_0.pdb , 7 atoms found Succeed to read file ...four_phenol_0_h.pdb , 13 atoms found Succeed to save file ...four_phenol_0_h.pdb Succeed to read file ...four_phenol_0_h.pdb , 13 atoms found Succeed to save file ...four_phenol_0_h.pdb Succeed to save file ...four_phenol_1.pdb Succeed to read file ...four_phenol_1.pdb , 7 atoms found Succeed to read file ...four_phenol_1_h.pdb , 13 atoms found Succeed to save file ...four_phenol_1_h.pdb Succeed to read file ...four_phenol_1_h.pdb , 13 atoms found Succeed to save file ...four_phenol_1_h.pdb Succeed to save file ...four_phenol_2.pdb Succeed to read file ...four_phenol_2.pdb , 7 atoms found Succeed to read file ...four_phenol_2_h.pdb , 13 atoms found Succeed to save file ...four_phenol_2_h.pdb Succeed to read file ...four_phenol_2_h.pdb , 13 atoms found Succeed to save file ...four_phenol_2_h.pdb Succeed to save file ...four_phenol_3.pdb Succeed to read file ...four_phenol_3.pdb , 7 atoms found Succeed to read file ...four_phenol_3_h.pdb , 13 atoms found Succeed to save file ...four_phenol_3_h.pdb Succeed to read file ...four_phenol_3_h.pdb , 13 atoms found Succeed to save file ...four_phenol_3_h.pdb Succeed to save concat file: ...four_phenol_h.pdb 0 >>> phenol_coor = pdb_manip.Coor(os.path.join(TEST_OUT,\ 'four_phenol_h.pdb')) #doctest: +ELLIPSIS Succeed to read file ...four_phenol_h.pdb , 52 atoms found """ full_coor = pdb_manip.Coor(pdb_in) # Change first residue to 1, as it is the res from rdkit output res_list = full_coor.get_attribute_selection(attribute='res_num') pdb_list = [] pdb_del_list = [] for i, res in enumerate(res_list): # Extract residue one_res = full_coor.select_part_dict(selec_dict={'res_num': [res]}) out_pdb = '{}_{}.pdb'.format(pdb_in[:-4], i) one_res.write_pdb(out_pdb) pdb_del_list.append(out_pdb) # Add hydrogens out_h_pdb = '{}_{}_h.pdb'.format(pdb_in[:-4], i) charge = add_hydrogen_rdkit_one_mol(out_pdb, smile, out_h_pdb) pdb_list.append(out_h_pdb) pdb_del_list.append(out_h_pdb) # Update residue number: one_res_h = pdb_manip.Coor(out_h_pdb) one_res_h.change_pdb_field(change_dict={"res_num": i + 1}) one_res_h.write_pdb(out_h_pdb, check_file_out=False) pdb_manip.Coor.concat_pdb(*pdb_list, pdb_out=pdb_out) # Delete intermediate files for pdb in pdb_del_list: os_command.delete_file(pdb) return charge
def test_autodock_cpu(tmp_path, capsys): # Convert to str to avoid problem with python 3.5 TEST_OUT = str(tmp_path) # Redirect pdb_manip logs pdb_manip.show_log() # Extract center and max_sizer: lig_coor = pdb_manip.Coor(os.path.join(TEST_PATH, 'lig.pdbqt')) center_lig = lig_coor.center_of_mass() max_size = lig_coor.get_max_size() print("Center coordinates is {:.1f} {:.1f} {:.1f}, maximum dimension" " is {:.1f} Å".format(*center_lig, max_size)) captured = capsys.readouterr() assert bool( re.match( "File name doesn't finish with .pdb read it as .pdb" " anyway\n" 'Succeed to read file .+/input/lig.pdbqt , 50 ' 'atoms found\nDo a rotation of 99.71°\nCenter ' 'coordinates is 13.1 22.5 5.5, maximum dimension is ' '18.0 Å\n', captured.out)) # Create Docking object test_dock = docking.Docking(name='test_autodock', rec_pdbqt=os.path.join(TEST_PATH, 'rec.pdbqt'), lig_pdbqt=os.path.join(TEST_PATH, 'lig.pdbqt')) # Prepare Grid spacing = 0.375 test_dock.prepare_grid(out_folder=TEST_OUT, spacing=spacing, center=center_lig, grid_npts=[int(max_size / spacing)] * 3) captured = capsys.readouterr() assert bool( re.match( ("python2.+ .+prepare_gpf4.py -r rec.pdbqt -l lig.pdbqt -o " "test_autodock.gpf -p npts=48,48,48 -p " "gridcenter=13.08,22.52,5.54\nautogrid4 -p test_autodock.gpf -l " "test_autodock.gpf_log"), captured.out)) test_dock.run_autodock_cpu(out_folder=TEST_OUT, nrun=2) rmsd_list = test_dock.compute_dock_rmsd(test_dock.lig_pdbqt) assert len(rmsd_list) == 2 assert rmsd_list[0] < 15 assert len(test_dock.affinity) == 2 assert test_dock.affinity[1]['affinity'] < -10 assert bool(test_dock.lig_pdbqt.endswith("lig.pdbqt")) assert bool(test_dock.rec_pdbqt.endswith("rec.pdbqt")) assert bool(test_dock.dock_pdb.endswith("test_autodock_vmd.pdb")) assert bool(test_dock.dock_log.endswith("test_autodock.dlg")) assert bool(test_dock.gpf.endswith("test_autodock.gpf")) # Read test_dock.dock_pdb coor_dock = pdb_manip.Multi_Coor(test_dock.dock_pdb) assert len(coor_dock.coor_list) == 2 assert len(coor_dock.coor_list[0].atom_dict) == 50
def test_pdb2pqr_ph4_7_12_charmm(tmp_path): """ Test pdb2pqr at ph 4, 7 and 12 with the charmm ff. """ ff = "CHARMM" pdb_manip.show_log() ########################################## # ## Compute protonation at PH 4.0 ### ########################################## out_file = os.path.join(tmp_path, '4N1M_charmm_ph4.pqr') pdb2pqr.compute_pdb2pqr(os.path.join(PDB_4N1M), out_file, ff=ff, ph=4.0) prot_coor = pdb_manip.Coor(out_file) assert prot_coor.num == 2559 HSD_index = prot_coor.get_index_selection({ 'res_name': ['HSD'], 'name': ['CA'] }) HSE_index = prot_coor.get_index_selection({ 'res_name': ['HSE'], 'name': ['CA'] }) HSP_index = prot_coor.get_index_selection({ 'res_name': ['HSP'], 'name': ['CA'] }) assert len(HSD_index) == 0 assert len(HSE_index) == 0 assert len(HSP_index) == 5 ########################################## # ## Compute protonation at PH 7.0 ### ########################################## out_file = os.path.join(tmp_path, '4N1M_charmm_ph7.pqr') pdb2pqr.compute_pdb2pqr(os.path.join(PDB_4N1M), out_file, ff=ff, ph=7.0) prot_coor = pdb_manip.Coor(out_file) assert prot_coor.num == 2549 HSD_index = prot_coor.get_index_selection({ 'res_name': ['HSD'], 'name': ['CA'] }) HSE_index = prot_coor.get_index_selection({ 'res_name': ['HSE'], 'name': ['CA'] }) HSP_index = prot_coor.get_index_selection({ 'res_name': ['HSP'], 'name': ['CA'] }) assert len(HSD_index) == 4 assert len(HSE_index) == 0 assert len(HSP_index) == 1 ########################################## # ## Compute protonation at PH 10.0 ### out_file = os.path.join(tmp_path, '4N1M_charmm_ph10.pqr') pdb2pqr.compute_pdb2pqr(os.path.join(PDB_4N1M), out_file, ff=ff, ph=10.0) prot_coor = pdb_manip.Coor(out_file) assert prot_coor.num == 2548 HSD_index = prot_coor.get_index_selection({ 'res_name': ['HSD'], 'name': ['CA'] }) HSE_index = prot_coor.get_index_selection({ 'res_name': ['HSE'], 'name': ['CA'] }) HSP_index = prot_coor.get_index_selection({ 'res_name': ['HSP'], 'name': ['CA'] }) assert len(HSD_index) == 5 assert len(HSE_index) == 0 assert len(HSP_index) == 0
def test_prepare_ligand_recetor(tmp_path, capsys): # Convert to str to avoid problem with python 3.5 TEST_OUT = str(tmp_path) # Redirect pdb_manip logs pdb_manip.show_log() # Read 1hsg.pdb, extract lig.pdb and rec.pdb coor_1hsg = pdb_manip.Coor(os.path.join(TEST_PATH, '1hsg.pdb')) captured = capsys.readouterr() assert bool( re.match("Succeed to read file .+input/1hsg.pdb , 1686 atoms found\n", captured.out)) # Extratc Protein: # Keep only amino acid rec_coor = coor_1hsg.select_part_dict( selec_dict={'res_name': pdb_manip.PROTEIN_AA}) out_rec = os.path.join(TEST_OUT, 'rec.pdb') rec_coor.write_pdb(out_rec) captured = capsys.readouterr() assert bool(re.match("Succeed to save file .+rec.pdb\n", captured.out)) # Extract ligand: lig_coor = coor_1hsg.select_part_dict( selec_dict={'res_name': 'MK1'}) out_lig = os.path.join(TEST_OUT, 'lig.pdb') lig_coor.write_pdb(out_lig) captured = capsys.readouterr() assert bool(re.match("Succeed to save file .+lig.pdb\n", captured.out)) # Extract ligand center of mass and maximum dimension: center_lig = lig_coor.center_of_mass() max_size = lig_coor.get_max_size() print("Center coordinates is {:.1f} {:.1f} {:.1f}, maximum dimension" " is {:.1f} Å".format(*center_lig, max_size)) captured = capsys.readouterr() assert bool(re.match('Do a rotation of 99.65°\nCenter coordinates is 13.1' ' 22.5 5.6, maximum dimension is 16.0 Å\n', captured.out)) # Create Docking object test_dock = docking.Docking('test', rec_pdb=out_rec, lig_pdb=out_lig) # Prepare receptor test_dock.prepare_receptor() captured = capsys.readouterr() assert bool(re.match( ("python2.+ .+/prepare_receptor4.py -r .+/rec.pdb" " -A checkhydrogens -o .+/rec.pdbqt\n"), captured.out)) # Check that receptor is fine coor_rec = pdb_manip.Coor(test_dock.rec_pdbqt) print('Protein atom number : {}'.format(coor_rec.select_part_dict( {'res_name': pdb_manip.PROTEIN_AA}).num)) captured = capsys.readouterr() assert bool(re.match( "Succeed to read file .+rec.pdbqt , 1844 atoms found\n" "Protein atom number : 1844\n", captured.out)) # Prepare Ligand test_dock.prepare_ligand(rigid=True) captured = capsys.readouterr() assert bool(re.match("python.+ .+prepare_ligand4.py -l lig.pdb -B " "none -A hydrogens -o lig.pdbqt -Z\n", captured.out)) # Check that ligand pdbqt is fine coor_lig = pdb_manip.Coor(test_dock.lig_pdbqt) print('Protein atom number : {}'.format(coor_lig.select_part_dict( {'res_name': pdb_manip.PROTEIN_AA}).num)) captured = capsys.readouterr() assert bool(re.match( "Succeed to read file .+lig.pdbqt , 50 atoms found\n" "Protein atom number : 0\n", captured.out))
def test_autodock_2_rigid(tmp_path, capsys): # Convert to str to avoid problem with python 3.5 TEST_OUT = str(tmp_path) # Redirect pdb_manip logs pdb_manip.show_log() # Extract center and max_sizer: lig_coor = pdb_manip.Coor(os.path.join(TEST_PATH, 'lig.pdbqt')) center_lig = lig_coor.center_of_mass() max_size = lig_coor.get_max_size() print("Center coordinates is {:.1f} {:.1f} {:.1f}, maximum dimension" " is {:.1f} Å".format(*center_lig, max_size)) captured = capsys.readouterr() assert bool(re.match('Succeed to read file .+/input/lig.pdbqt , 50 ' 'atoms found\nDo a rotation of 99.71°\nCenter ' 'coordinates is 13.1 22.5 5.5, maximum dimension is ' '18.0 Å\n', captured.out)) # Create Docking object test_dock = docking.Docking( name='test_autodock_2', rec_pdbqt=os.path.join(TEST_PATH, 'rec.pdbqt'), lig_pdbqt=os.path.join(TEST_PATH, 'lig.pdbqt')) out_dock = os.path.join(TEST_OUT, '{}_dock.pdb'.format('test_autodock_2')) test_dock.run_autodock_docking(out_dock, num_modes=2, center=center_lig, grid_size=[max_size + 5] * 3) captured = capsys.readouterr() capture_line = captured.out.split('\n') assert bool(re.match( ("python2.+ .+prepare_gpf4.py -r rec.pdbqt -l lig.pdbqt -o " "test_autodock_2_dock.gpf -p npts=62,62,62 -p " "gridcenter=13.08,22.52,5.54"), capture_line[0])) assert bool(re.match( ("autogrid4 -p test_autodock_2_dock.gpf " "-l test_autodock_2_dock.gpf_log"), capture_line[1])) rmsd_list = test_dock.compute_dock_rmsd(test_dock.lig_pdbqt) assert len(rmsd_list) == 2 assert rmsd_list[0] < 15 assert len(test_dock.affinity) == 2 assert test_dock.affinity[1]['affinity'] < -10 captured = capsys.readouterr() test_dock.display() captured = capsys.readouterr() assert bool(re.match( ("name : test_autodock_2\n" "lig_pdbqt : .+lig.pdbqt\n" "rec_pdbqt : .+rec.pdbqt\n" "dock_pdb : .+test_autodock_2_dock_vmd.pdb\n" "dock_log : .+test_autodock_2_dock.dlg\n" "gpf : .+test_autodock_2_dock.gpf\n" "affinity : {1: .+affinity': -.+}}\n" ), captured.out))
def test_autodock_rigid(tmp_path, capsys): # Convert to str to avoid problem with python 3.5 TEST_OUT = str(tmp_path) # Redirect pdb_manip logs pdb_manip.show_log() # Extract center and max_sizer: lig_coor = pdb_manip.Coor(os.path.join(TEST_PATH, 'lig.pdbqt')) center_lig = lig_coor.center_of_mass() max_size = lig_coor.get_max_size() print("Center coordinates is {:.1f} {:.1f} {:.1f}, maximum dimension" " is {:.1f} Å".format(*center_lig, max_size)) captured = capsys.readouterr() assert bool(re.match('Succeed to read file .+/input/lig.pdbqt , 50 ' 'atoms found\nDo a rotation of 99.71°\nCenter ' 'coordinates is 13.1 22.5 5.5, maximum dimension is ' '18.0 Å\n', captured.out)) # Create Docking object test_dock = docking.Docking( name='test_autodock', rec_pdbqt=os.path.join(TEST_PATH, 'rec.pdbqt'), lig_pdbqt=os.path.join(TEST_PATH, 'lig.pdbqt')) # Prepare Grid spacing = 0.375 test_dock.prepare_grid(out_folder=TEST_OUT, spacing=spacing, center=center_lig, grid_npts=[int(max_size / spacing)] * 3) captured = capsys.readouterr() assert bool(re.match( ("python2.+ .+prepare_gpf4.py -r rec.pdbqt -l lig.pdbqt -o " "test_autodock.gpf -p npts=48,48,48 -p " "gridcenter=13.08,22.52,5.54\nautogrid4 -p test_autodock.gpf -l " "test_autodock.gpf_log"), captured.out)) test_dock.run_autodock(out_folder=TEST_OUT, nrun=1) rmsd_list = test_dock.compute_dock_rmsd(test_dock.lig_pdbqt) assert len(rmsd_list) >= 1 assert rmsd_list[0] < 15 captured = capsys.readouterr() test_dock.display() captured = capsys.readouterr() assert bool(re.match( ("name : test_autodock\n" "lig_pdbqt : .+lig.pdbqt\n" "rec_pdbqt : .+rec.pdbqt\n" "dock_pdb : .+test_autodock_vmd.pdb\n" "dock_log : .+test_autodock.dlg\n" "gpf : .+test_autodock.gpf\n" "affinity : {1: .+affinity': -.+}}\n" ), captured.out))
def add_hydrogen_rdkit_one_mol(pdb_in, smile, pdb_out): """Add hydrogen to a pdb file using the ``rdkit`` library: :param pdb_in: pdb input :type pdb_in: str :param pdb_out: pdb output :type pdb_out: str :Example: >>> from pdb_manip_py import pdb_manip >>> pdb_manip.show_log() >>> TEST_OUT = getfixture('tmpdir') >>> # print(TEST_OUT) >>> add_hydrogen_rdkit_one_mol(pdb_in=os.path.join(TEST_PATH,'phenol.pdb')\ ,smile="C1=CC=C(C=C1)O",\ pdb_out=os.path.join(TEST_OUT,'phenol_h.pdb')) #doctest: +ELLIPSIS Succeed to read file ...phenol_h.pdb , 13 atoms found Succeed to save file ...phenol_h.pdb 0 >>> phenol_coor = pdb_manip.Coor(os.path.join(TEST_OUT,'phenol_h.pdb'))\ #doctest: +ELLIPSIS Succeed to read file .../phenol_h.pdb , 13 atoms found .. warning: """ try: from rdkit.Chem import AllChem as Chem # from rdkit.Chem import rdMolAlign as align except ImportError: logger.error('Could not load rdkit \nInstall it using conda:\n' 'conda install -c conda-forge rdkit') sys.exit(1) lig_pdb = Chem.MolFromPDBFile(pdb_in, removeHs=True) lig_smile = Chem.MolFromSmiles(smile) # Need to count the number of molecule pdb_atom_num = lig_pdb.GetNumAtoms() smile_atom_num = lig_smile.GetNumAtoms() # If more than one molecule, add them # in the smile string if pdb_atom_num != smile_atom_num: mol_num = pdb_atom_num / smile_atom_num smile_list = [smile] * int(mol_num) lig_smile = Chem.MolFromSmiles('.'.join(smile_list)) # Assign bond order on pdb using smile informations newMol = Chem.AssignBondOrdersFromTemplate(lig_smile, lig_pdb) # Add hydrogens to lig_smile, using lig_pdb as coordinates constraints # This way is better than adding h to lig_pdb # because acpype experience some issue lig_smile_h = Chem.AddHs(lig_smile) Chem.ConstrainedEmbed(lig_smile_h, newMol) Chem.MolToPDBFile(lig_smile_h, pdb_out) # OLD WAY : # Add hydrogens # newMol_h = Chem.AddHs(newMol) # # Need to define how to match atoms form pdb to smile # match_atom = newMol_h.GetSubstructMatch(lig_smile) # cmap = {match_atom[i]: lig_pdb.GetConformer(). # GetAtomPosition(match_atom[i]) for i in range(len(match_atom))} # # Hydrogens coordinates need to be computed # # While keeping heavy atoms coordinates # Chem.EmbedMolecule(newMol_h, coordMap=cmap) # # Align new coordinates to old one # align.AlignMol(newMol_h, newMol, # atomMap=[[i, i] for i in range(len(match_atom))]) # Save coordinates # Chem.MolToPDBFile(newMol_h, pdb_out) # Change UNL residue name to original one coor_start = pdb_manip.Coor(pdb_in) res_name_list_start = coor_start.get_attribute_selection( attribute='res_name') if len(res_name_list_start) > 1: res_name_list_start.remove('UNL') coor = pdb_manip.Coor(pdb_out) index_list = coor.get_index_selection(selec_dict={'res_name': ['UNL']}) coor.change_index_pdb_field( index_list, change_dict={'res_name': res_name_list_start[0]}) coor.write_pdb(pdb_out, check_file_out=False) # Return charge return Chem.GetFormalCharge(lig_smile)