def load_file(self, fname: Union[Path, str]): """ Load the info or h5 file and extract the info Args: fname: String- or Path-like file reference Returns: """ if not isinstance(fname, Path): fname = Path(fname) if not fname.exists(): raise NoFileExists("cannot find %s!" % fname) os.chdir(fname.parent) if fname.suffix == '.h5': self._get_fromH5(fname) else: self._get_fromApp(fname)
def load_gmxmmpbsa_info(fname): """ Loads up an gmx_MMPBSA info file and returns a mmpbsa_data instance with all of the data available in numpy arrays if numpy is available. The returned object is a mmpbsa_data instance. change the structure to get more easy way to graph per residue mmpbsa_data attributes: ----------------------- o Derived from "dict" o Each solvent model is a dictionary key for a numpy array (if numpy is available) or array.array (if numpy is unavailable) for each of the species (complex, receptor, ligand) present in the calculation. o The alanine scanning mutant data is under another dict denoted by the 'mutant' key. Data Layout: ------------ Model | Dictionary Key | Data Keys Available ------------------------------------------------------------------- Generalized Born | 'gb' | EGB, ESURF, * Poisson-Boltzmann | 'pb' | EPB, EDISPER, ECAVITY, * 3D-RISM (GF) | 'rism gf' | 3D-RISM (Standard)| 'rism std' | Normal Mode | 'nmode' | Quasi-harmonic | 'qh' | * == TOTAL, VDW, EEL, 1-4 EEL, 1-4 VDW, BOND, ANGLE, DIHED The keys above are entries for the main dict as well as the sub-dict whose key is 'mutant' in the main dict. Each entry in the main (and mutant sub-) dict is, itself, a dict with 1 or 3 keys; 'complex', 'receptor', 'ligand'; where 'receptor' and 'ligand' are missing for stability calculations. If numpy is available, all data will be numpy.ndarray instances. Otherwise, all data will be array.array instances. All of the objects referenced by the listed 'Dictionary Key's are dicts in which the listed 'Data Keys Available' are keys to the data arrays themselves Examples: --------- # Load numpy for our analyses (optional) import numpy as np # Load the _MMPBSA_info file: mydata = load_mmpbsa_info('_MMPBSA_info') # Access the complex GB data structure and calculate the autocorr. fcn. autocorr = np.correlate(mydata['gb']['complex']['TOTAL'], mydata['gb']['complex']['TOTAL']) # Calculate the standard deviation of the alanine mutant receptor in PB print mydata.mutant['pb']['receptor']['TOTAL'].std() """ if not isinstance(fname, Path): fname = Path(fname) if not fname.exists(): raise NoFileExists("cannot find %s!" % fname) os.chdir(fname.parent) app = main.MMPBSA_App(MPI) info = infofile.InfoFile(app) info.read_info(fname) app.normal_system = app.mutant_system = None app.parse_output_files() return_data = mmpbsa_data(app) # Since Decomp data is parsed in a memory-efficient manner (by not storing # all of the data in arrays, but rather by printing each data point as it's # parsed), we need to handle the decomp data separately here # Open Complex fixed structure to assign per-(residue/wise) residue name try: complex_str = parmed.read_PDB(app.FILES.complex_fixed) except: complex_str = parmed.read_PDB(app.FILES.prefix + 'COM.pdb') # Get receptor and ligand masks mut_index = None rec = {} mut_rec = {} rmstr = app.INPUT['receptor_mask'].strip(':') rml = rmstr.split(',') for x in rml: if len(x.split('-')) > 1: start, end = x.split('-') for i in range(int(start), int(end) + 1): residue = complex_str.residues[i - 1] icode = f'{residue.insertion_code}' if icode: icode = ':' + icode rec[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) mut_rec[i] = ( f"{residue.chain}:{residue.name}:{residue.number}" + icode) if app.INPUT['mutant_res'] == ( f"{residue.chain}:{residue.number}" + icode): mut_rec[i] = ( f"{residue.chain}:{app.INPUT['mutant']}:{residue.number}" + icode) else: i = int(x) residue = complex_str.residues[i - 1] icode = f'{residue.insertion_code}' if icode: icode = ':' + icode rec[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) mut_rec[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) if app.INPUT['mutant_res'] == ( f"{residue.chain}:{residue.number}" + icode): mut_rec[i] = ( f"{residue.chain}:{app.INPUT['mutant']}:{residue.number}" + icode) lig = {} mut_lig = {} lmstr = app.INPUT['ligand_mask'].strip(':') lml = lmstr.split(',') for x in lml: if len(x.split('-')) > 1: start, end = x.split('-') for i in range(int(start), int(end) + 1): residue = complex_str.residues[i - 1] icode = f'{residue.insertion_code}' if icode: icode = ':' + icode lig[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) mut_lig[i] = ( f"{residue.chain}:{residue.name}:{residue.number}" + icode) if app.INPUT['mutant_res'] == ( f"{residue.chain}:{residue.number}" + icode): mut_lig[i] = ( f"{residue.chain}:{app.INPUT['mutant']}:{residue.number}" + icode) else: i = int(x) residue = complex_str.residues[i - 1] icode = f'{residue.insertion_code}' if icode: icode = ':' + icode lig[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) mut_lig[i] = (f"{residue.chain}:{residue.name}:{residue.number}" + icode) if app.INPUT['mutant_res'] == ( f"{residue.chain}:{residue.number}" + icode): mut_lig[i] = ( f"{residue.chain}:{app.INPUT['mutant']}:{residue.number}" + icode) com = rec.copy() com.update(lig) com_res_info = [] for key, value in sorted(com.items()): com_res_info.append(value) rec_res_info = [] for key, value in rec.items(): rec_res_info.append(value) lig_res_info = [] for key, value in lig.items(): lig_res_info.append(value) mut_com_res_info = [] mut_com = mut_rec.copy() mut_com.update(mut_lig) for key, value in sorted(mut_com.items()): mut_com_res_info.append(value) mut_rec_res_info = [] for key, value in mut_rec.items(): mut_rec_res_info.append(value) mut_lig_res_info = [] for key, value in mut_lig.items(): mut_lig_res_info.append(value) if not app.INPUT['alarun']: return_data.mutant = {} if app.INPUT['decomprun']: # Simplify the decomp class instance creation if app.INPUT['idecomp'] in (1, 2): DecompClass = lambda x, part: APIDecompOut(x, part, app) else: DecompClass = lambda x, part: APIPairDecompOut(x, part, app) if not app.INPUT['mutant_only']: # Do normal GB if app.INPUT['gbrun']: return_data['decomp'] = {'gb': {}} return_data['decomp']['gb']['complex'] = DecompClass( app.FILES.prefix + 'complex_gb.mdout', com_res_info).array_data if not app.stability: return_data['decomp']['gb']['receptor'] = DecompClass( app.FILES.prefix + 'receptor_gb.mdout', rec_res_info).array_data return_data['decomp']['gb']['ligand'] = DecompClass( app.FILES.prefix + 'ligand_gb.mdout', lig_res_info).array_data return_data['decomp']['gb']['delta'] = get_delta_decomp( app, 'gb', return_data['decomp']) # Do normal PB if app.INPUT['pbrun']: return_data['decomp'] = {'pb': {}} return_data['decomp']['pb']['complex'] = DecompClass( app.FILES.prefix + 'complex_pb.mdout', com_res_info).array_data if not app.stability: return_data['decomp']['pb']['receptor'] = DecompClass( app.FILES.prefix + 'receptor_pb.mdout', rec_res_info).array_data return_data['decomp']['pb']['ligand'] = DecompClass( app.FILES.prefix + 'ligand_pb.mdout', lig_res_info).array_data return_data['decomp']['pb']['delta'] = get_delta_decomp( app, 'pb', return_data['decomp']) if app.INPUT['alarun']: # Do mutant GB if app.INPUT['gbrun']: return_data.mutant['decomp'] = {'gb': {}} return_data.mutant['decomp']['gb']['complex'] = DecompClass( app.FILES.prefix + 'mutant_complex_gb.mdout', mut_com_res_info).array_data if not app.stability: return_data.mutant['decomp']['gb'][ 'receptor'] = DecompClass( app.FILES.prefix + 'mutant_receptor_gb.mdout', mut_rec_res_info).array_data return_data.mutant['decomp']['gb']['ligand'] = DecompClass( app.FILES.prefix + 'mutant_ligand_gb.mdout', mut_lig_res_info).array_data return_data.mutant['decomp']['gb'][ 'delta'] = get_delta_decomp( app, 'gb', return_data.mutant['decomp']) # Do mutant PB if app.INPUT['pbrun']: return_data.mutant['decomp'] = {'pb': {}} return_data.mutant['decomp']['pb']['complex'] = DecompClass( app.FILES.prefix + 'mutant_complex_pb.mdout', mut_com_res_info).array_data if not app.stability: return_data.mutant['decomp']['pb'][ 'receptor'] = DecompClass( app.FILES.prefix + 'mutant_receptor_pb.mdout', mut_rec_res_info).array_data return_data.mutant['decomp']['pb']['ligand'] = DecompClass( app.FILES.prefix + 'mutant_ligand_pb.mdout', mut_lig_res_info).array_data return_data.mutant['decomp']['pb'][ 'delta'] = get_delta_decomp( app, 'pb', return_data.mutant['decomp']) else: return_data.mutant = None app_namespace = SimpleNamespace(FILES=app.FILES, INPUT=app.INPUT, numframes=app.numframes, numframes_nmode=app.numframes_nmode) return return_data, app_namespace
def load_gmxmmpbsa_info(fname: Union[Path, str]): """ Loads up an gmx_MMPBSA info or h5 file and returns a dictionary with all energy terms and a namespace with some variables needed in gmx_MMPBSA_ana Depending on the data type store the variable can be a Dataframe, string or scalar Data attributes: ----------------------- o All attributes from dict o Each solvent model is a dictionary key for a numpy array (if numpy is available) or array.array (if numpy is unavailable) for each of the species (complex, receptor, ligand) present in the calculation. o The alanine scanning mutant data is under another dict denoted by the 'mutant' key. Data Layout: ------------ Model | Dict Key | Data Keys Available -------------------------------------------------------------- Generalized Born | 'gb' | EGB, ESURF, * Poisson-Boltzmann | 'pb' | EPB, EDISPER, ECAVITY, * 3D-RISM (GF) | 'rism gf' | POLAR SOLV, APOLAR SOLV, * 3D-RISM (Standard) | 'rism std' | 3D-RISM (PCPLUS) |'rism pcplus'| Normal Mode | 'nmode' | Quasi-harmonic | 'qh' | Interaction entropy | 'ie' | C2 Entropy | 'c2' | * == TOTAL, VDW, EEL, 1-4 EEL, 1-4 VDW, BOND, ANGLE, DIHED The keys above are entries for the main dict as well as the sub-dict whose key is 'mutant' in the main dict. Each entry in the main (and mutant sub-) dict is, itself, a dict with 1 or 3 keys; 'complex', 'receptor', 'ligand'; where 'receptor' and 'ligand' are missing for stability calculations. If numpy is available, all data will be numpy.ndarray instances. Otherwise, all data will be array.array instances. All of the objects referenced by the listed 'Dictionary Key's are dicts in which the listed 'Data Keys Available' are keys to the data arrays themselves Examples: --------- # Load numpy for our analyses (optional) import numpy as np # Load the _MMPBSA_info file: mydata = load_mmpbsa_info('_MMPBSA_info') # Access the complex GB data structure and calculate the autocorr. fcn. autocorr = np.correlate(mydata['gb']['complex']['TOTAL'], mydata['gb']['complex']['TOTAL']) # Calculate the standard deviation of the alanine mutant receptor in PB print mydata.mutant['pb']['receptor']['TOTAL'].stdev() """ if not isinstance(fname, Path): fname = Path(fname) if not fname.exists(): raise NoFileExists("cannot find %s!" % fname) os.chdir(fname.parent) d_mmpbsa = MMPBSA_API() d_mmpbsa.load_file(fname) return d_mmpbsa.get_energy(), d_mmpbsa.app_namespace
def load_gmxmmpbsa_info(fname): """ Loads up an gmx_MMPBSA info file and returns a mmpbsa_data instance with all of the data available in numpy arrays if numpy is available. The returned object is a mmpbsa_data instance. change the structure to get more easy way to graph per residue mmpbsa_data attributes: ----------------------- o Derived from "dict" o Each solvent model is a dictionary key for a numpy array (if numpy is available) or array.array (if numpy is unavailable) for each of the species (complex, receptor, ligand) present in the calculation. o The alanine scanning mutant data is under another dict denoted by the 'mutant' key. Data Layout: ------------ Solvent Model | Dictionary Key | Data Keys Available ------------------------------------------------------------------- Generalized Born | 'gb' | EGB, ESURF, * Poisson-Boltzmann | 'pb' | EPB, EDISPER, ECAVITY, * 3D-RISM (GF) | 'rism gf' | 3D-RISM (Standard)| 'rism std' | Normal Mode | 'nmode' | Quasi-harmonic | 'qh' | * == TOTAL, VDW, EEL, 1-4 EEL, 1-4 VDW, BOND, ANGLE, DIHED The keys above are entries for the main dict as well as the sub-dict whose key is 'mutant' in the main dict. Each entry in the main (and mutant sub-) dict is, itself, a dict with 1 or 3 keys; 'complex', 'receptor', 'ligand'; where 'receptor' and 'ligand' are missing for stability calculations. If numpy is available, all data will be numpy.ndarray instances. Otherwise, all data will be array.array instances. All of the objects referenced by the listed 'Dictionary Key's are dicts in which the listed 'Data Keys Available' are keys to the data arrays themselves Examples: --------- # Load numpy for our analyses (optional) import numpy as np # Load the _MMPBSA_info file: mydata = load_mmpbsa_info('_MMPBSA_info') # Access the complex GB data structure and calculate the autocorr. fcn. autocorr = np.correlate(mydata['gb']['complex']['TOTAL'], mydata['gb']['complex']['TOTAL']) # Calculate the standard deviation of the alanine mutant receptor in PB print mydata.mutant['pb']['receptor']['TOTAL'].std() """ if not HAS_NUMPY: warnings.warn( 'numpy was not found. Data will be packed in normal Python ' 'arrays. Install numpy for more efficient array handling.', NotImplemented) if not os.path.exists(fname): raise NoFileExists("cannot find %s!" % fname) app = main.MMPBSA_App(MPI) info = infofile.InfoFile(app) info.read_info(fname) app.normal_system = app.mutant_system = None app.parse_output_files() return_data = mmpbsa_data(app) # Since Decomp data is parsed in a memory-efficient manner (by not storing # all of the data in arrays, but rather by printing each data point as it's # parsed), we need to handle the decomp data separately here if not app.INPUT['alarun']: return_data.mutant = None lig_res = None if app.INPUT['decomprun']: # Simplify the decomp class instance creation if app.INPUT['idecomp'] in (1, 2): DecompClass = lambda x, y, z=None: APIDecompOutGMX( x, y, app.mpi_size, app.INPUT['dec_verbose'], app.numframes, lig_num=z) else: DecompClass = lambda x, y, z=None: APIPairDecompOutGMX( x, y, app.mpi_size, app.INPUT['dec_verbose'], app.numframes, lig_num=z) if not app.INPUT['mutant_only']: # Do normal GB if app.INPUT['gbrun']: return_data['decomp'] = {'gb': {}} return_data['decomp']['gb']['complex'] = DecompClass( app.FILES.prefix + 'complex_gb.mdout', app.INPUT['surften']).array_data com_res = [] for k in return_data['decomp']['gb']['complex']['TDC']: if k not in com_res: com_res.append(k) if not app.stability: return_data['decomp']['gb']['receptor'] = DecompClass( app.FILES.prefix + 'receptor_gb.mdout', app.INPUT['surften']).array_data rec_res = [] for k in return_data['decomp']['gb']['receptor']['TDC']: if k not in rec_res: rec_res.append(k) lig_res = com_res[len(rec_res):] return_data['decomp']['gb']['ligand'] = DecompClass( app.FILES.prefix + 'ligand_gb.mdout', app.INPUT['surften'], lig_res).array_data return_data['decomp']['gb']['delta'] = get_delta_decomp( app, 'gb', return_data['decomp']) # Do normal PB if app.INPUT['pbrun']: return_data['decomp'] = {'pb': {}} return_data['decomp']['pb']['complex'] = DecompClass( app.FILES.prefix + 'complex_pb.mdout', app.INPUT['surften']).array_data if not app.stability: return_data['decomp']['pb']['receptor'] = DecompClass( app.FILES.prefix + 'receptor_pb.mdout', app.INPUT['surften']).array_data return_data['decomp']['pb']['ligand'] = DecompClass( app.FILES.prefix + 'ligand_pb.mdout', app.INPUT['surften'], lig_res).array_data return_data['decomp']['pb']['delta'] = get_delta_decomp( app, 'pb', return_data['decomp']) if app.INPUT['alarun']: # Do mutant GB if app.INPUT['gbrun']: return_data.mutant['decomp'] = {'gb': {}} return_data.mutant['decomp']['gb']['complex'] = DecompClass( app.FILES.prefix + 'mutant_complex_gb.mdout', app.INPUT['surften']).array_data if not app.stability: return_data.mutant['decomp']['gb'][ 'receptor'] = DecompClass( app.FILES.prefix + 'mutant_receptor_gb.mdout', app.INPUT['surften']).array_data return_data.mutant['decomp']['gb']['ligand'] = DecompClass( app.FILES.prefix + 'mutant_ligand_gb.mdout', app.INPUT['surften'], lig_res).array_data return_data.mutant['decomp']['gb'][ 'delta'] = get_delta_decomp( app, 'gb', return_data.mutant['decomp']) # Do mutant PB if app.INPUT['pbrun']: return_data.mutant['decomp'] = {'pb': {}} return_data.mutant['decomp']['pb']['complex'] = DecompClass( app.FILES.prefix + 'mutant_complex_pb.mdout', app.INPUT['surften']).array_data if not app.stability: return_data.mutant['decomp']['pb'][ 'receptor'] = DecompClass( app.FILES.prefix + 'mutant_receptor_pb.mdout', app.INPUT['surften']).array_data return_data.mutant['decomp']['pb']['ligand'] = DecompClass( app.FILES.prefix + 'mutant_ligand_pb.mdout', app.INPUT['surften'], lig_res).array_data return_data.mutant['decomp']['pb'][ 'delta'] = get_delta_decomp( app, 'pb', return_data.mutant['decomp']) else: return_data.mutant = None return return_data, app