Source code for schrodinger.application.desmond.stage.app.watermap

import future.utils
import os
import re
import shutil
from past.utils import old_div

import numpy as np

from schrodinger import structure
from schrodinger.application.desmond import cmj
from schrodinger.application.desmond import constants
from schrodinger.application.desmond import envir
from schrodinger.application.desmond import util
from schrodinger.utils import sea

from ..jobs import DesmondJob

WATERMAP_TYPE = 's_watermap_type'
WM_WATERMAP = 'watermap'
WM_LIGAND = 'ligand'
WM_RECEPTOR = 'receptor'
WM_CONTINUOUS = 'watermap continuous'

__all__ = ['WaterMapCluster', 'WaterMapAnaJob', 'WaterMapPostAnalysis']


[docs]class WaterMapCluster(cmj.StageBase): """ """ NAME = "watermap_cluster" PARAM = cmj._create_param_when_needed([ """ DATA = { ligand_file = ? protein_file = ? input_name = "$MAINJOBNAME-water.maegz" output_name = "$MAINJOBNAME-cluster.maegz" hs_radius = 1.0 dcutoff = 2.0 grid_width = 0.5 enable_continuous = 1 twobody = 0 distance = 10.0 cpu = 1 } VALIDATE = { ligand_file = [{type = str _check = multisim_file_exists} {type = none}] protein_file = [{type = str _check = multisim_file_exists} {type = none}] input_name = {type = str } output_name = {type = str } hs_radius = {type = "float+"} dcutoff = {type = "float+"} grid_width = {type = "float+"} enable_continuous = {type = int } twobody = {type = int } distance = {type = "float+"} cpu = {type = int1} } """, ])
[docs] def __init__(self, *arg, **kwarg): """ """ cmj.StageBase.__init__(self, *arg, **kwarg) self._pack = "\\tar cfz"
# __init__
[docs] def crunch(self): """ """ self._print("debug", "In WaterMapCluster.crunch") param = self.param pj0 = self.get_prejobs()[0] jobname, dir = self._get_jobname_and_dir(pj0) water_file = os.path.join(dir, jobname + "-water.maegz") if (not os.path.isdir(dir)): os.makedirs(dir) util.chdir(dir) # Combines the water .maegz files to a single file. for pj in self.get_prejobs(): for st in structure.StructureReader( os.path.join(pj.dir, pj.jobname + "-water.maegz")): st.append(water_file) lig_file = os.path.join(cmj.ENGINE.base_dir, param.ligand_file.val) pro_file = os.path.join(cmj.ENGINE.base_dir, param.protein_file.val) # Defines input file names. fname_in = jobname + "-in.cms" fname_in1 = jobname + ".inp" fname_in2 = jobname + "-ligand.mae" fname_in3 = jobname + "-protein.mae" # Prepares input files. util.symlink(util.relpath(pj0.input.cms[0]), fname_in) util.symlink(util.relpath(lig_file), fname_in2) util.symlink(util.relpath(pro_file), fname_in3) print("{\n" + param.bval.__str__(tag="setbyuser") + "}\n", file=open(fname_in1, "w")) # Prepares the launch command. jlaunch_cmd = [ os.path.join(envir.CONST.SCHRODINGER, "run"), "-FROM", "watermap", "watermap_backend_startup.py", "-JOBNAME", jobname, "-cpu", str(param.cpu.val), fname_in1, ] # Creates a new job. new_job = DesmondJob(pj0.task, pj0.gid, pj0.permanent_restrain, pj0.permanent_group, jobname, pj0, self, jlaunch_cmd, dir) new_job.need_host = False new_job.other_parent = self.get_prejobs()[1:] new_job.output.add(os.path.abspath(param.output_name.val)) new_job.output.add(os.path.abspath(jobname + ".log")) new_job.is_output = False self.add_jobs([new_job, *self.get_prejobs()]) self._print("debug", "Out WaterMapCluster.crunch")
[docs]class WaterMapAnaJob(cmj.Job):
[docs] def __init__(self, output_file, cluster_file, ligand_file, protein_file, water_file, input_cms, input_trj, do_not_return_trajectory, cavity, cavity_cns, hbond_stat, ene, ligand_distance=10.0, sampling_freq=50, hs_radius=1.0, *arg, **kwarg): self.output_file = output_file self.cluster_file = cluster_file self.ligand_file = ligand_file self.protein_file = protein_file self.water_file = water_file self.input_cms = input_cms self.input_trj = input_trj self.do_not_return_trajectory = do_not_return_trajectory self.output_cms = [] self.ene = ene self.cavity = cavity self.cavity_cns = cavity_cns self.hbond_stat = hbond_stat self.ligand_distance = ligand_distance self.sampling_freq = sampling_freq self.hs_radius = hs_radius self._watermap_st = None self.trans_x = 0 self.trans_y = 0 self.trans_z = 0 cmj.Job.__init__(self, *arg, **kwarg)
def __getstate__(self, state=None): self._watermap_st = None return cmj.Job.__getstate__(self, state)
[docs] def run(self): self.read_cluster_file() self.get_translation_vector() self.transform_watermap() self.calculateAverageDipole() self.calculateWaterMapDensity() self.writeHSWater() self.writeFrameWater() self.average_hbond() self.average_cavity() self.average_cavity_cns() self.writeGridData() if not self.do_not_return_trajectory: self.transformWaterMapTrajectory() self.average_energy() self.decorate_watermap() self.write_watermap() self.status.set(cmj.JobStatus.SUCCESS)
[docs] def read_cluster_file(self): struc_reader = structure.StructureReader(self.cluster_file) self._watermap_st = next(struc_reader)
[docs] def get_translation_vector(self): struc_reader = structure.StructureReader(self.ligand_file) _st = next(struc_reader) self.trans_x = _st.property['r_watermap_trans1'] self.trans_y = _st.property['r_watermap_trans2'] self.trans_z = _st.property['r_watermap_trans3']
[docs] def average_cavity(self): import array ncavity = len(self.cavity) weight = old_div(1.0, float(ncavity)) ene_fname = self.jobname + '-continuous_ene.maegz' atom_total = structure.Structure.read(ene_fname).atom_total cavity = atom_total * [0.0] for cavity_fname in self.cavity: byte_count = os.path.getsize(cavity_fname) if atom_total * 4 == byte_count: # dealing with floats arr = array.array('f', []) elif atom_total * 8 == byte_count: # dealing with doubles arr = array.array('d', []) else: raise RuntimeError( 'ERROR: Size of cavity file %s is incompatible with either a 32-bit or \ a 64-bit representation of %i particles' % (cavity_fname, atom_total)) f = open(cavity_fname, 'rb') arr.fromfile(f, atom_total) f.close() cavlist = arr.tolist() for i in range(len(cavity)): cavity[i] += cavlist[i] * weight cavity_fname = self.jobname + '-continuous_cavity' arr = array.array('f', []) arr.fromlist(cavity) f = open(cavity_fname, "wb") arr.tofile(f) f.close()
[docs] def average_cavity_cns(self): import schrodinger.application.desmond.cns_io as cns_io ncavity = len(self.cavity_cns) if ncavity > 0: weight = old_div(1.0, float(ncavity)) cns_data = cns_io.CNSData(self.cavity_cns[0], False) shape = cns_data.grid_data.shape cns_data.grid_data = np.zeros(shape) else: raise IOError('ERROR: Missing cavity files') for cns_fname in self.cavity_cns: cns = cns_io.CNSData(cns_fname, False) if cns_data.grid_data.shape != cns.grid_data.shape: raise ValueError('ERROR: Mismatched cavity shapes') cns_data.grid_data += cns.grid_data * weight cavity_cns_fname = self.jobname + '-continuous_cavity.cns' remark = "Generated from WaterMap\n" remark += "REMARKS Map type: 1Fo - 1Fc Regular\n" cns_data.write(cavity_cns_fname, remark) self.output.add(os.path.abspath(cavity_cns_fname))
[docs] def average_hbond(self): if len(self.hbond_stat) == 0: return st = self._watermap_st re_hbond = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)', re.IGNORECASE) hbond_pw = st.atom_total * [0.0] hbond_lw = st.atom_total * [0.0] hbond_ww = st.atom_total * [0.0] hbond_occ = st.atom_total * [0] for hbond_fname in self.hbond_stat: lines = open(hbond_fname).readlines() for line in lines[1:]: hbond_match = re_hbond.match(line) hbond = hbond_match.groups() i = int(hbond[0]) - 1 hbond_pw[i] += float(hbond[1]) hbond_lw[i] += float(hbond[2]) hbond_ww[i] += float(hbond[3]) hbond_occ[i] += int(hbond[4]) for i, a in enumerate(st.atom): if hbond_occ[i] == 0: a.property['r_wmap_hb_pw'] = 0.0 a.property['r_wmap_hb_lw'] = 0.0 a.property['r_wmap_hb_ww'] = 0.0 else: a.property['r_wmap_hb_pw'] = old_div(hbond_pw[i], hbond_occ[i]) a.property['r_wmap_hb_lw'] = old_div(hbond_lw[i], hbond_occ[i]) a.property['r_wmap_hb_ww'] = old_div(hbond_ww[i], hbond_occ[i])
[docs] def average_energy(self): st = self._watermap_st ncluster = st.atom_total pw_ene_list = [] ww_ene_list = [] for i in range(ncluster): pw_ene_list.append([]) ww_ene_list.append([]) re_comment = re.compile(r'^#') re_dist_ene = re.compile( r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)', re.IGNORECASE) for seg_fname in self.ene: seg_lines = open(seg_fname).readlines() for line in seg_lines: if re_comment.match(line): continue ene_match = re_dist_ene.match(line) if ene_match: de = ene_match.groups() if len(de) == 6 and float(de[3]) <= self.hs_radius: # 4: PE_sw 5: PE_ww pw_ene_list[int(de[1])].append(float(de[4])) ww_ene_list[int(de[1])].append(float(de[5])) for a in st.atom: i = a.index - 1 pw_avg_ene = 0.0 if pw_ene_list[i]: pw_avg_ene = old_div(sum(pw_ene_list[i]), len(pw_ene_list[i])) a.property['r_wmap_pw_pe'] = pw_avg_ene ww_avg_ene = 0.0 if ww_ene_list[i]: ww_avg_ene = old_div(sum(ww_ene_list[i]), len(ww_ene_list[i])) a.property['r_wmap_ww_pe'] = ww_avg_ene
[docs] def transform_watermap(self): for a in self._watermap_st.atom: a.x += self.trans_x a.y += self.trans_y a.z += self.trans_z
[docs] def write_watermap(self): jobname = self.jobname self._watermap_st.write(jobname + '_temp_wm.maegz') for a in self._watermap_st.atom: for k in list(a.property): if k.find('_wmap_') > 0: del a.property[k] self._watermap_st.write(self.output_file) if (os.path.exists(self.ligand_file)): st_reader = structure.StructureReader(self.ligand_file) for st in st_reader: if not st.property["s_m_title"]: st.property["s_m_title"] = "sampling_coordinates" st.property[WATERMAP_TYPE] = WM_LIGAND for i in range(1, st.atom_total + 1): st.atom[i].x += self.trans_x st.atom[i].y += self.trans_y st.atom[i].z += self.trans_z st.append(self.output_file) if (os.path.exists(self.protein_file)): st_reader = structure.StructureReader(self.protein_file) for st in st_reader: if not st.property["s_m_title"]: st.property["s_m_title"] = jobname + "-receptor" st.property[WATERMAP_TYPE] = WM_RECEPTOR st.append(self.output_file)
[docs] def decorate_watermap(self): jobname = self.jobname nframe = structure.count_structures(self.water_file) for a in self._watermap_st.atom: a.property['r_watermap_density'] = old_div( a.property['i_wmap_ntime'], float(nframe)) try: a.property['r_watermap_potential_energy'] = a.property[ 'r_wmap_pw_pe'] + a.property['r_wmap_ww_pe'] except: a.property['r_watermap_potential_energy'] = a.property[ 'r_watermap_sw_energy'] + a.property['r_watermap_ww_energy'] a.property['r_watermap_entropy'] = -( a.property['r_wmap_t_ent'] + a.property['r_wmap_r_ent']) * 0.300 a.property['r_watermap_hbond_ww'] = a.property['r_wmap_hb_ww'] a.property['r_watermap_hbond_pw'] = a.property['r_wmap_hb_pw'] a.property['r_watermap_hbond_lw'] = a.property['r_wmap_hb_lw'] a.property['i_watermap_site_num'] = a.index try: a.property['r_watermap_twobody_entropy'] = a.property[ 'r_wmap_tb_ent'] except: pass self._watermap_st.property["s_m_title"] = jobname + "-watermap" self._watermap_st.property[WATERMAP_TYPE] = WM_WATERMAP file_map = { 's_watermap_water_density_file': jobname + '-water.cns', 's_watermap_tpi_density_file': jobname + '-continuous_cavity.cns', 's_watermap_cms_file': jobname + '-out.cms', 's_watermap_hs_file': jobname + '-hs.maegz', 's_watermap_frame_file': jobname + '-frame.maegz', 's_watermap_continuous_file': jobname + '-continuous.maegz', 's_watermap_continuous_score_file': jobname + '-continuous_score.maegz', 's_watermap_occupancy_file': jobname + '-continuous_occupancy.cns', 's_watermap_energy_file': jobname + '-continuous_energy.cns', 's_watermap_entropy_file': jobname + '-continuous_entropy.cns', 's_watermap_free_energy_file': jobname + '-continuous_free_energy.cns', } for i, output in enumerate(self.output_cms): file_map["s_watermap_cms_%s_file" % str(i)] = self.jobname + '_' + str(i) + '-out.cms' if self.do_not_return_trajectory: del file_map['s_watermap_cms_file'] for i, output in enumerate(self.output_cms): del file_map["s_watermap_cms_%s_file" % str(i)] for k, v in future.utils.viewitems(file_map): if os.path.exists(v): self._watermap_st.property[k] = os.path.join(jobname, v)
[docs] def calculateAverageDipole(self): nhs = self._watermap_st.atom_total for i in range(nhs): fname = self.jobname + '.' + str(i + 1) + '.maegz' st = structure.Structure.read(fname) xyz = st.getXYZ() all_dipole = [] for j in range(0, len(xyz), 3): oh1 = xyz[j + 1] - xyz[j] oh2 = xyz[j + 2] - xyz[j] dp = oh1 + oh2 dp /= np.inner(dp, dp) # normalize # we want to use reduced unit (0, 1). # dp *= 2.18 # multiply by TIP4P dipole moment all_dipole.append(dp) m = np.mean(np.array(all_dipole), 0) self._watermap_st.atom[i + 1].property['r_watermap_dipole_x'] = m[0] self._watermap_st.atom[i + 1].property['r_watermap_dipole_y'] = m[1] self._watermap_st.atom[i + 1].property['r_watermap_dipole_z'] = m[2]
[docs] def calculateWaterMapDensity(self): import schrodinger.application.desmond.gaussian_filter as gaussian_filter fname = self.water_file if not os.path.exists(fname): fname = self.jobname + '-water.mae' if not os.path.exists(fname): print('Water files, %s and %s, do not exist.' % (self.jobname + '-water.mae', fname)) return st_reader = structure.StructureReader(self.ligand_file) ligand_locations = [] for st in st_reader: for a in st.atom: if a.atomic_number != 1: ligand_locations.append((a.x, a.y, a.z)) ligand_loc_array = np.array(ligand_locations) distance = self.ligand_distance bin_spacing = 0.5 span = 3 min = ligand_loc_array.min(axis=0) max = ligand_loc_array.max(axis=0) min = ligand_loc_array.min( axis=0) - distance - span * bin_spacing + np.array( [self.trans_x, self.trans_y, self.trans_z]) max = ligand_loc_array.max( axis=0) + distance + span * bin_spacing + np.array( [self.trans_x, self.trans_y, self.trans_z]) min = min[::-1] max = max[::-1] min = np.floor(old_div(min, bin_spacing)) * bin_spacing - 0.5 * bin_spacing max = np.ceil(old_div(max, bin_spacing)) * bin_spacing + 0.5 * bin_spacing gf = gaussian_filter.GaussianFilter(bin_spacing, span) nframes = structure.count_structures(fname) st_reader = structure.StructureReader(fname) for st in st_reader: locations = [] for a in st.atom: if a.atomic_number > 1 and a.property['i_wmap_buffer'] < 2: locations.append((a.x + self.trans_x, a.y + self.trans_y, a.z + self.trans_z)) # Ev:98142 Renormalize the data in the solvent density cns file such that it is a true density weights = np.ones(len(locations)) w = 1.0 / float(nframes) / bin_spacing**3 for i in range(weights.size): weights[i] = w loc_array = np.array(locations) gf.apply(loc_array, weights, max, min) remark = 'Generated from WaterMap\n' remark += 'REMARKS Map type: 1Fo - 1Fc Regular\n' output_cns = self.jobname + '-water.cns' gf.write(output_cns, remark) self.output.add(os.path.abspath(output_cns)) self.water_grid_density = gf.histogram
[docs] def transformWaterMapTrajectory(self): import schrodinger.application.desmond.packages.traj as traj for i, (input_cms, input_trj) in enumerate(zip(self.input_cms, self.input_trj)): output_name = self.jobname + '_' + str(i) output_trj = output_name + '-out_trj' matrix = np.array([self.trans_x, self.trans_y, self.trans_z]) tr = traj.read_traj(input_trj) for fr in tr: pos = fr.pos() pos += matrix traj.write_traj(tr, output_trj) output_cms = output_name + '-out.cms' self.output_cms.append(output_cms) output_idx = output_name + '-out_trj.idx' s = 'structure = %s\n' % output_cms s += 'trajectory = %s\n' % output_trj open(output_idx, 'w').write(s) if os.path.exists(output_cms): os.remove(output_cms) for st in structure.StructureReader(input_cms): if st.property[ constants.CT_TYPE] == constants.CT_TYPE.VAL.FULL_SYSTEM: st.property['s_chorus_trajectory_file'] = output_idx st.property['s_m_original_cms_file'] = output_cms else: try: del st.property['s_chorus_trajectory_file'] del st.property['s_m_original_cms_file'] except: continue for i in range(st.atom_total): st.atom[i + 1].x += self.trans_x st.atom[i + 1].y += self.trans_y st.atom[i + 1].z += self.trans_z st.append(output_cms) self.output.add(os.path.abspath(output_cms)) self.output.add(os.path.abspath(output_idx)) self.output.add(os.path.abspath(output_trj))
[docs] def writeHSWater(self): import schrodinger.structutils.transform as transform hs_fname = self.jobname + '-hs.maegz' self.output.add(os.path.abspath(hs_fname)) ncluster = self._watermap_st.atom_total sampling_freq = self.sampling_freq for i in range(ncluster): fname = self.jobname + '.' + str(i + 1) + '.maegz' st = structure.Structure.read(fname) hs_list = [] for a in st.atom: mol_num = a.molecule_number - 1 if mol_num % sampling_freq == 0: hs_list.append(a.index) for k in list(a.property): if k.find('_wmap_') > 0: del a.property[k] if hs_list: hs_st = st.extract(hs_list) transform.translate_structure(hs_st, self.trans_x, self.trans_y, self.trans_z) hs_st.title = self.jobname + '.' + str(i + 1) hs_st.append(hs_fname)
[docs] def writeFrameWater(self): one_water_st = None frame_water_map = {} frame_fname = self.jobname + '-frame.maegz' self.output.add(os.path.abspath(frame_fname)) ncluster = self._watermap_st.atom_total sampling_freq = self.sampling_freq for i in range(ncluster): fname = self.jobname + '.' + str(i + 1) + '.maegz' st = structure.Structure.read(fname) if not one_water_st: one_water_st = st.extract([1, 2, 3]) for a in st.atom: wmap_time = a.property['i_wmap_time'] if wmap_time % sampling_freq == 0: wmap_time = str(wmap_time) if wmap_time not in frame_water_map: frame_water_map[wmap_time] = [] frame_water_map[wmap_time].append(a.xyz) for i in range(len(frame_water_map)): name = str(i * sampling_freq) if name not in frame_water_map: continue atom_list = frame_water_map[name] if len(atom_list) % 3 != 0: print( '# of atoms in frame water does not match with # of water molecules.' ) return st = one_water_st.copy() for j in range(1, old_div(len(atom_list), 3)): st.extend(one_water_st) for a in st.atom: a.x = atom_list[a.index - 1][0] + self.trans_x a.y = atom_list[a.index - 1][1] + self.trans_y a.z = atom_list[a.index - 1][2] + self.trans_z a.property['i_watermap_time'] = i * sampling_freq for k in list(a.property): if k.find('_wmap_') > 0: del a.property[k] st.title = self.jobname + '.' + str(i) st.append(frame_fname)
[docs] def writeGridData(self): import struct ene_fname = self.jobname + '-continuous_ene.maegz' tpi_fname = self.jobname + '-continuous_cavity' old_tpi_fname = self.jobname + '-grid_cavity' if not (os.path.exists(ene_fname) and (os.path.exists(tpi_fname) or os.path.exists(old_tpi_fname))): return st = structure.Structure.read(ene_fname) """ shape = self.water_grid_density.shape nele = shape[0]*shape[1]*shape[2] if st.atom_total != nele: print '# of grids between energy and density does not match. (%d %d)' % ( st.atom_total, nele) return n = 1 for i in range(shape[2]): for j in range(shape[1]): for k in range(shape[0]): st.atom[n].property['r_watermap_density'] = self.water_grid_density[k, j, i] n += 1 """ byte_count = os.path.getsize(tpi_fname) if st.atom_total * 4 == byte_count: # dealing with floats unpack_str = '<f' element_size = 4 elif st.atom_total * 8 == byte_count: # dealing with doubles unpack_str = '<d' element_size = 8 else: print( 'WARNING: number of grids between energy and tpi does not match; analysis aborted!' ) return f = open(tpi_fname, 'rb') for n in range(st.atom_total): ele = f.read(element_size) cavity, = struct.unpack(unpack_str, ele) st.atom[n + 1].property['r_watermap_cavity'] = float(cavity) f.close() # translate back to original coordinates for a in st.atom: a.x += self.trans_x a.y += self.trans_y a.z += self.trans_z st.property[WATERMAP_TYPE] = WM_CONTINUOUS file_map = { 's_watermap_tpi_density_file': self.jobname + '-tpi.cns', 's_watermap_occupancy_file': self.jobname + '-continuous_occupancy.cns', 's_watermap_energy_file': self.jobname + '-continuous_energy.cns', 's_watermap_entropy_file': self.jobname + '-continuous_entropy.cns', 's_watermap_free_energy_file': self.jobname + '-continuous_free_energy.cns', } for k, v in future.utils.viewitems(file_map): if os.path.exists(v): st.property[k] = v all_grid_fname = self.jobname + '-continuous_score.maegz' st.write(all_grid_fname) # delete grids that have zero density deleted_atoms = [] for a in st.atom: if ((a.property['r_watermap_density'] == 0.0) and (a.property['r_watermap_cavity'] < 0.5)): deleted_atoms.append(a.index) st.deleteAtoms(deleted_atoms) for a in st.atom: a.name = 'GR%d' % a.index grid_fname = self.jobname + '-continuous.maegz' st.write(grid_fname) if (os.path.exists(self.ligand_file)): st_reader = structure.StructureReader(self.ligand_file) for st in st_reader: if not st.property["s_m_title"]: st.property["s_m_title"] = "sampling_coordinates" st.property[WATERMAP_TYPE] = WM_LIGAND for i in range(1, st.atom_total + 1): st.atom[i].x += self.trans_x st.atom[i].y += self.trans_y st.atom[i].z += self.trans_z st.append(all_grid_fname) st.append(grid_fname) if (os.path.exists(self.protein_file)): st_reader = structure.StructureReader(self.protein_file) for st in st_reader: if not st.property["s_m_title"]: st.property["s_m_title"] = self.jobname + "-receptor" st.property[WATERMAP_TYPE] = WM_RECEPTOR st.append(all_grid_fname) st.append(grid_fname) self.output.add(os.path.abspath(all_grid_fname)) self.output.add(os.path.abspath(grid_fname)) # return all grid cns files cns_fnames = [ self.jobname + "-continuous_occupancy.cns", self.jobname + "-continuous_entropy.cns", self.jobname + "-continuous_energy.cns", self.jobname + "-continuous_free_energy.cns", ] for fname in cns_fnames: if os.path.exists(fname): self.output.add(os.path.abspath(fname)) else: self._print("quiet", "%s is not found.")
[docs]class WaterMapPostAnalysis(cmj.StageBase): """ """ NAME = "watermap_post_analysis" CMD = os.path.join(envir.CONST.SCHRODINGER, "run") PARAM = cmj._create_param_when_needed([ """ DATA = { ligand_file = ? protein_file = ? water_name = "$MAINJOBNAME-water.maegz" output = "$MAINJOBNAME_wm.maegz" do_not_return_trajectory = false } VALIDATE = { ligand_file = [{type = str _check = multisim_file_exists} {type = none}] protein_file = [{type = str _check = multisim_file_exists} {type = none}] water_name = {type = str} output = {type = str} do_not_return_trajectory = {type = bool} } """, ])
[docs] def __init__(self, *arg, **kwarg): """ """ cmj.StageBase.__init__(self, *arg, **kwarg)
# __init__
[docs] def crunch(self): """ """ self._print("debug", "In WaterMapPostAnalysis.crunch") param = self.param base_dir = cmj.ENGINE.base_dir pj0 = self.get_prejobs()[0] jobname, dir = self._get_jobname_and_dir(pj0) water_file = os.path.join(dir, jobname + "-water.maegz") lig_file = os.path.join(base_dir, param.ligand_file.val) pro_file = os.path.join(base_dir, param.protein_file.val) cluster_file = jobname + "-cluster.maegz" out_fname = param.output.val pre_cms = [] frameset = [] cavity = [] cavity_cns = [] hbond_stat = [] ene = [] for pj in self.get_prejobs(): pre_dir = pj.dir pre_cms.append(os.path.join(pre_dir, pj.input.cms[0])) pre_cfg = sea.Map(open(pj.input.incfg_file()).read()) frameset.append(os.path.join(pre_dir, pre_cfg.vrun_frameset.val)) try: ene.append( os.path.join( pre_dir, pre_cfg.backend.vrun.plugin.SpatialEnergyGroup. data_name.val)) except: pass cavity.append( os.path.join( pre_dir, pre_cfg.backend.vrun.plugin.TestParticleInsertion. file_tpi_cavity.val)) cavity_cns.append( os.path.join( pre_dir, pre_cfg.backend.vrun.plugin.TestParticleInsertion. file_tpi_cns.val)) hbond_stat.append( os.path.join( pre_dir, pre_cfg.backend.vrun.plugin.HbondStatisticsWM. file_hbond_statistics.val)) if (not os.path.isdir(dir)): raise IOError('ERROR: Missing directory "%s"' % dir) util.chdir(dir) new_job = WaterMapAnaJob( out_fname, cluster_file, lig_file, pro_file, water_file, pre_cms, frameset, param.do_not_return_trajectory.val, cavity, cavity_cns, hbond_stat, ene, ligand_distance=10.0, sampling_freq=50, hs_radius=1.0, jobname=jobname, parent=pj0, stage=self, jlaunch_cmd=lambda job: job.run(), dir=dir, ) new_job.output.add(os.path.abspath(out_fname)) new_job.output.add(os.path.abspath(jobname + ".log")) new_job.output.set_struct_file(os.path.abspath(out_fname)) self.add_job(new_job) self._print("debug", "Out WaterMapPostAnalysis.crunch")
[docs] def hook_captured_successful_job(self, job): """ """ import schrodinger.application.watermap.utils as wm_utils out_fname = self.param.output.val top_out_fname = os.path.join(cmj.ENGINE.base_dir, out_fname) shutil.copyfile(os.path.abspath(out_fname), top_out_fname) archive_fname = wm_utils.archive_wm(top_out_fname, cmj.ENGINE.base_dir) cmj.ENGINE.JOBBE.addOutputFile(os.path.basename(archive_fname)) os.remove(top_out_fname)