def _get_fromApp(self, ifile): app = main.MMPBSA_App(MPI) info = infofile.InfoFile(app) info.read_info(ifile) app.normal_system = app.mutant_system = None app.parse_output_files() self.app_namespace = self._get_namespace(app) self._oringin = {'normal': app.calc_types.normal, 'mutant': app.calc_types.mutant, 'decomp_normal': app.calc_types.decomp_normal, 'decomp_mutant': app.calc_types.decomp_mutant, 'mutant-normal': app.calc_types.mut_norm, # 'decomp_mutant-normal': app.calc_types.decomp_mut_norm } self.data = copy(self._oringin) self._get_frames() self._get_data(None)
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 gmxmmpbsa(): stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) formatter = logging.Formatter("[%(levelname)-7s] %(message)s") stream_handler.setFormatter(formatter) logging.basicConfig( level=logging.DEBUG, format="[%(levelname)-7s] %(message)s", handlers=[logging.FileHandler("gmx_MMPBSA.log", 'w'), stream_handler]) # Just for compatibility as mpi4py works as serial when run without mpirun # (since v1.4.2) if len(sys.argv) > 1 and sys.argv[1] in ['MPI', 'mpi']: from mpi4py import MPI else: # If we're not running "gmx_MMPBSA MPI", bring MPI into the top-level namespace # (which will overwrite the MPI from mpi4py, which we *want* to do in serial) from GMXMMPBSA.fake_mpi import MPI # Set up error/signal handlers main.setup_run() # Instantiate the main MMPBSA_App app = main.MMPBSA_App(MPI) # Read the command-line arguments try: app.get_cl_args(sys.argv[1:]) except CommandlineError as e: sys.stderr.write('%s: %s' % (type(e).__name__, e) + '\n') sys.exit(1) if app.FILES.createinput is not None: args_list = create_input_args(app.FILES.createinput) app.input_file.print_contents('mmpbsa.in', args_list) logging.info( f'Input file creation successful. Path: {Path("mmpbsa.in").absolute()}' ) sys.exit(0) # Perform our MMPBSA --clean now if app.FILES.clean: logging.info('Cleaning temporary files and quitting.\n') app.remove(-1) sys.exit(0) # See if we wanted to print out our input file options if app.FILES.infilehelp: app.input_file.print_contents(sys.stdout) sys.exit(0) # If we're not rewriting output do whole shebang, otherwise load info and parms # Throw up a barrier before and after running the actual calcs if not app.FILES.rewrite_output: try: app.read_input_file() except InputError as e: sys.stderr.write('%s: %s' % (type(e).__name__, e) + '\n') sys.stderr.write(' Enter `%s --help` for help\n' % (split(sys.argv[0])[1])) sys.exit(1) app.process_input() app.check_for_bad_input() app.make_prmtops() app.loadcheck_prmtops() app.file_setup() app.run_mmpbsa() # If we are rewriting output, load the info and check prmtops else: info = InfoFile(app) info.read_info() app.loadcheck_prmtops() # Now we parse the output, print, and finish app.parse_output_files() app.write_final_outputs() app.finalize()
def gmxmmpbsa(): # Adapted to run with MPI ? if len(sys.argv) > 1 and sys.argv[1] in ['MPI', 'mpi']: args = sys.argv args.pop(1) # remove mpi arg before passed it to app try: from mpi4py import MPI except ImportError: raise MMPBSA_Error( 'Could not import mpi4py package! Use serial version ' 'or install mpi4py.') else: # If we're not running "gmx_MMPBSA MPI", bring MPI into the top-level namespace # (which will overwrite the MPI from mpi4py, which we *want* to do in serial) from GMXMMPBSA.fake_mpi import MPI args = sys.argv # Set up error/signal handlers main.setup_run() # Instantiate the main MMPBSA_App app = main.MMPBSA_App(MPI) # Read the command-line arguments try: app.get_cl_args(args[1:]) except CommandlineError as e: sys.stderr.write('%s: %s' % (type(e).__name__, e) + '\n') sys.exit(1) # Perform our MMPBSA --clean now if app.FILES.clean: sys.stdout.write('Cleaning temporary files and quitting.\n') app.remove(0) sys.exit(0) # See if we wanted to print out our input file options if app.FILES.infilehelp: app.input_file.print_contents(sys.stdout) sys.exit(0) # If we're not rewriting output do whole shebang, otherwise load info and parms # Throw up a barrier before and after running the actual calcs if not app.FILES.rewrite_output: try: app.read_input_file() except InputError as e: sys.stderr.write('%s: %s' % (type(e).__name__, e) + '\n') sys.stderr.write(' Enter `%s --help` for help\n' % (split(sys.argv[0])[1])) sys.exit(1) app.process_input() app.check_for_bad_input() app.loadcheck_prmtops() app.file_setup() app.run_mmpbsa() # If we are rewriting output, load the info and check prmtops else: info = InfoFile(app) info.read_info() app.loadcheck_prmtops() # Now we parse the output, print, and finish app.parse_output_files() app.write_final_outputs() app.finalize()
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