def load_sample_simulation(mof='single', setup='run', tests_dir=tests_dir, parameters=k_parameters.copy()): """ Load a sample simulation object from the tests directory """ from thermof import Simulation if mof == 'single': trial = os.path.join(tests_dir, 'ideal-mof-trial') if setup == 'run': sample_simulation = Simulation(read=os.path.join(trial, 'Run1'), setup='run', parameters=parameters) elif setup == 'trial': sample_simulation = Simulation(read=trial, setup='trial', parameters=parameters) else: trial = os.path.join(tests_dir, 'ip-mof-trial') if setup == 'run': sample_simulation = Simulation(read=os.path.join(trial, 'Run1'), setup='run', parameters=parameters) elif setup == 'trial': sample_simulation = Simulation(read=trial, setup='trial', parameters=parameters) return sample_simulation
def test_simulation_read_run(): """Test Simulation class read method for reading a single run with read_run""" par = Parameters() par.k['read_thermo'] = True par.k['read_info'] = True par.thermof['kpar'] = par.k run_dir = os.path.join(trial_dir, 'Run1') run_data = read_run(run_dir, k_par=par.k) sim = Simulation(read=run_dir, parameters=par) sim.read(run_dir, setup='run') with open(thermo_ref_file, 'r') as tref: thermo_ref = yaml.load(tref) assert sim.run == run_data assert sim.run['thermo'] == thermo_ref assert len(sim) == 1 assert str(sim) == 'Run1'
def test_simulation_get_plot_data_for_trial(): """Test Simulation class get_plot_data method for pulling correct data for different plots of a trial""" par = Parameters() sim = Simulation(read=trial_dir, parameters=par, setup='trial') with open(time_ref_file, 'r') as tiref: time_ref = yaml.load(tiref) assert get_plot_data(sim, 'k')['x'] == time_ref assert get_plot_data(sim, 'k_sub')['x'] == time_ref assert get_plot_data(sim, 'k')['legend'] == sim.trial['runs']
def test_simulation_read_trial_set(): """Test Simulation class read method for reading a trial set""" par = Parameters() par.k['isotropic'] = True par.k['average'] = True par.thermof['kpar'] = par.k trial_set = read_trial_set(trial_set_dir, k_par=par.k) sim = Simulation(read=trial_set_dir, setup='trial_set', parameters=par) assert trial_set == sim.trial_set assert len(sim) == 4 assert str(sim) == 'ideal-mof-trial-set'
def test_simulation_get_plot_data_for_run(): """Test Simulation class get_plot_data method for pulling correct data for different plots of a run""" par = Parameters() par.k['read_thermo'] = True par.thermof['kpar']['read_thermo'] = True par.thermof['kpar']['kb'] = 0.001987 run_dir = os.path.join(trial_dir, 'Run1') sim = Simulation(read=run_dir, parameters=par, setup='run') with open(k_ref_file, 'r') as kref: k_ref = yaml.load(kref) with open(time_ref_file, 'r') as tiref: time_ref = yaml.load(tiref) with open(thermo_ref_file, 'r') as tref: thermo_ref = yaml.load(tref) assert get_plot_data(sim, 'thermo') == thermo_ref k_plot_data = get_plot_data(sim, 'k') assert k_plot_data['x'] == time_ref assert k_plot_data['y'][sim.run['directions'].index('x')] == k_ref assert k_plot_data['legend'] == sim.run['directions']
def main(): parser = argparse.ArgumentParser( description=""" ---------------------------------------------------------------------------- ████████╗██╗ ██╗███████╗██████╗ ███╗ ███╗ ██████╗ ███████╗ ╚══██╔══╝██║ ██║██╔════╝██╔══██╗████╗ ████║██╔═══██╗██╔════╝ ██║ ███████║█████╗ ██████╔╝██╔████╔██║██║ ██║█████╗ ██║ ██╔══██║██╔══╝ ██╔══██╗██║╚██╔╝██║██║ ██║██╔══╝ ██║ ██║ ██║███████╗██║ ██║██║ ╚═╝ ██║╚██████╔╝██║ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ TherMOF: Thermal transport in Metal-Organic Frameworks ----------------------------------------------------------------------------- """, epilog=""" Example: python thermof_read.py IRMOF-1 would read simulation results from IRMOF-1 directory. You would need a Lammps log file and simpar.yaml (produced by thermof) to be able to read simulation results. """, formatter_class=argparse.RawDescriptionHelpFormatter) default_params = {} # Positional arguments parser.add_argument('simdir', type=str, help='Lammps simulation directory.') # Optional arguments parser.add_argument('--setup', '-s', default='run', type=str, metavar='', help='Simulation setup (run | trial | trial_set).') parser.add_argument('--no_parameters', '-np', action='store_true', default=False, help='Dont read simulation parameters, use default.') parser.add_argument('--plot', '-p', nargs='+', default=[], help='Plot HCACF, k, and thermodynamic properties.') parser.add_argument( '--kavg', '-k', nargs=2, default=[10, 20], help='Average thermal conductivity btw. given time interval (ps).') parser.add_argument('--write', '-w', action='store_true', default=False, help='Write results to a file.') # Parse arguments args = parser.parse_args() # Initialize simulation and read simdir = os.path.abspath(args.simdir) if args.no_parameters: sim = Simulation(setup=args.setup) else: sim = Simulation(setup=args.setup) sim.simdir = simdir sim.read_parameters() sim.parameters.thermof['kpar']['t0'] = int(args.kavg[0]) sim.parameters.thermof['kpar']['t1'] = int(args.kavg[1]) sim.read(simdir, setup=args.setup) # Plotting if len(args.plot) > 0: sim.parameters.plot = plot_parameters.copy() sim.parameters.plot['k_sub']['k_est_t0'] = int(args.kavg[0]) sim.parameters.plot['k_sub']['k_est_t1'] = int(args.kavg[1]) for plt in args.plot: sim.parameters.plot[plt]['save'] = os.path.join( simdir, '%s-%s.png' % (os.path.basename(simdir), plt)) sim.plot(plt)
def main(): parser = argparse.ArgumentParser( description=""" ---------------------------------------------------------------------------- ████████╗██╗ ██╗███████╗██████╗ ███╗ ███╗ ██████╗ ███████╗ ╚══██╔══╝██║ ██║██╔════╝██╔══██╗████╗ ████║██╔═══██╗██╔════╝ ██║ ███████║█████╗ ██████╔╝██╔████╔██║██║ ██║█████╗ ██║ ██╔══██║██╔══╝ ██╔══██╗██║╚██╔╝██║██║ ██║██╔══╝ ██║ ██║ ██║███████╗██║ ██║██║ ╚═╝ ██║╚██████╔╝██║ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ TherMOF: Thermal transport in Metal-Organic Frameworks ----------------------------------------------------------------------------- """, epilog=""" Example: >>> python thermof_write.py IRMOF-1.cif would read IRMOF-1 cif file, analyze topology, assign force field (default: UFF) and create input files for a Lammps simulation. >>> python thermof_write.py IRMOF-1.cif --forcefield UFF4MOF --fix MIN NPT NVT NVE --scheduler pbs would initialize Lammps simulation files with UFF4MOF force field for following procedure: Minimization, NPT, NVT, and NVE emsembles. It would also create a job submission script for pbs scheduler. """, formatter_class=argparse.RawDescriptionHelpFormatter) default_params = {} # Positional arguments parser.add_argument('molecule', type=str, help='Molecule file to read (must be in .cif format).') # Optional arguments parser.add_argument('--runs', '-r', default=1, type=int, metavar='', help='Number of runs (different seed number is used for each run).') parser.add_argument('--forcefield', '-ff', default='UFF', type=str, metavar='', help='Force field for molecule file ([UFF] / BTW_FF / Dreiding / UFF4MOF / Dubbeldam).') parser.add_argument('--fix', nargs='+', default=['NVT'], type=str, help='Lammps fix types (MIN / NPT / NVT / NVE).') parser.add_argument('--scheduler', default='slurm', type=str, metavar='', help='Job scheduler (pbs / [slurm] / slurm-scratch).') # Parse arguments args = parser.parse_args() # Initialize simulation simpar = Parameters() sim = Simulation(mof=args.molecule, parameters=simpar) mof_name = os.path.splitext(os.path.basename(args.molecule))[0] sim.simdir = os.path.join(os.path.dirname(args.molecule), mof_name) sim.parameters.lammps['force_field'] = args.forcefield sim.parameters.lammps['mol_ff'] = args.forcefield sim.parameters.thermof['fix'] = args.fix sim.parameters.job['scheduler'] = args.scheduler try: if args.runs == 1: sim.initialize() elif args.runs > 1: sim.initialize_runs(args.runs) except Exception as e: print(e)