Ejemplo n.º 1
0
 def test_custom_system(self, peek_from_file):
     simulation = simulate.Simulation(peek_from_file, mode="cpu")
     simulation.quench(kT=2,
                       n_steps=1e3,
                       shrink_kT=2,
                       shrink_steps=1e3,
                       shrink_period=20,
                       walls=False)
Ejemplo n.º 2
0
 def test_quench(self, peek_system):
     simulation = simulate.Simulation(peek_system, dt=0.0001, mode="cpu")
     simulation.quench(
         kT=2,
         n_steps=1e3,
         shrink_kT=8,
         shrink_steps=1e3,
         shrink_period=1,
         walls=False,
     )
Ejemplo n.º 3
0
 def test_walls_quench(self, peek_system_noH):
     simulation = simulate.Simulation(peek_system_noH, dt=0.001, mode="cpu")
     simulation.quench(
         kT=2,
         n_steps=1e3,
         shrink_kT=8,
         shrink_steps=1e3,
         shrink_period=20,
         walls=True,
     )
Ejemplo n.º 4
0
 def test_anneal_no_shrink(self, peek_system):
     simulation = simulate.Simulation(peek_system, dt=0.0001, mode="cpu")
     simulation.anneal(
         kT_init=4,
         kT_final=2,
         step_sequence=[1e3, 1e3],
         shrink_kT=None,
         shrink_steps=None,
         shrink_period=None,
         walls=False,
     )
Ejemplo n.º 5
0
 def test_walls_anneal(self, peek_system_noH):
     simulation = simulate.Simulation(peek_system_noH, dt=0.001, mode="cpu")
     simulation.anneal(
         kT_init=4,
         kT_final=2,
         step_sequence=[1e3, 1e3],
         shrink_kT=8,
         shrink_steps=1e3,
         shrink_period=20,
         walls=True,
     )
Ejemplo n.º 6
0
 def test_quench_no_shrink(self, peek_system):
     simulation = simulate.Simulation(peek_system,
                                      tau_p=0.1,
                                      dt=0.0001,
                                      mode="cpu")
     simulation.quench(
         kT=2,
         pressure=0.1,
         n_steps=1e3,
         shrink_kT=None,
         shrink_steps=None,
         shrink_period=None,
         walls=False,
     )
Ejemplo n.º 7
0
 def test_anneal_npt(self, pekk_system):
     simulation = simulate.Simulation(pekk_system,
                                      dt=0.0001,
                                      tau_p=0.1,
                                      mode="cpu")
     simulation.anneal(
         kT_init=4,
         kT_final=2,
         pressure=0.1,
         step_sequence=[1e3, 1e3],
         shrink_kT=8,
         shrink_steps=1e3,
         shrink_period=1,
         walls=False,
     )
Ejemplo n.º 8
0
 def test_bad_inputs(self, peek_system):
     simulation = simulate.Simulation(peek_system,
                                      tau_p=0.1,
                                      dt=0.0001,
                                      mode="cpu")
     # Only 1 of shrink params given
     with pytest.raises(ValueError):
         simulation.quench(
             kT=2,
             n_steps=1e3,
             shrink_kT=5,
             shrink_steps=None,
             shrink_period=None,
             walls=True,
         )
     # Pressure and walls quench
     with pytest.raises(ValueError):
         simulation.quench(
             kT=2,
             pressure=0.1,
             n_steps=1e3,
             shrink_kT=None,
             shrink_steps=None,
             shrink_period=None,
             walls=True,
         )
     # Pressure and walls anneal
     with pytest.raises(ValueError):
         simulation.anneal(
             kT_init=2,
             kT_final=1,
             step_sequence=[1e3, 1e3],
             pressure=0.1,
             shrink_kT=None,
             shrink_steps=None,
             shrink_period=None,
             walls=True,
         )
Ejemplo n.º 9
0
def sample(job):
    from uli_init import simulate, system
    from uli_init.utils import base_units, unit_conversions
    import numpy as np
    import logging

    with job:
        print(job.id)
        logging.info("Creating system...")
        if job.sp["system_type"] != "interface":
            system_parms = system.System(
                density=job.sp['density'],
                molecule=job.sp['molecule'],
                n_compounds=job.sp['n_compounds'],
                polymer_lengths=job.sp["polymer_lengths"],
                para_weight=job.sp['para_weight'],
                monomer_sequence=job.sp['monomer_sequence'],
                sample_pdi=job.doc.sample_pdi,
                pdi=job.sp['pdi'],
                Mn=job.sp['Mn'],
                Mw=job.sp['Mw'],
                seed=job.sp['system_seed'])
            system = system.Initializer(
                system=system_parms,
                system_type=job.sp["system_type"],
                forcefield=job.sp["forcefield"],
                remove_hydrogens=job.sp["remove_hydrogens"],
                **job.sp["kwargs"])
            if any(list(job.sp["box_constraints"].values())):
                system.target_box = system.set_target_box(
                    job.sp["box_constraints"]["x"],
                    job.sp["box_constraints"]["y"],
                    job.sp["box_constraints"]["z"])
            job.doc["target_volume"] = system.target_box

            shrink_kT = job.sp['shrink_kT']
            shrink_steps = job.sp['shrink_steps']
            shrink_period = job.sp['shrink_period']
            job.doc['num_para'] = system_parms.para
            job.doc['num_meta'] = system_parms.meta
            job.doc['num_compounds'] = system_parms.n_compounds
            job.doc['polymer_lengths'] = system_parms.polymer_lengths
            job.doc["chain_sequences"] = system_parms.molecule_sequences

        elif job.sp["system_type"] == "interface":
            slab_files = []
            ref_distances = []
            if job.doc['use_signac'] is True:
                signac_args = []
                if isinstance(job.sp['signac_args'], list):
                    slab_1_arg = job.sp['signac_args'][0]
                    signac_args.append(slab_1_arg)
                    if len(job.sp['signac_args']) == 2:
                        slab_2_arg = job.sp['signac_args'][1]
                        signac_args.append(slab_2_args)
                elif not isinstance(job.sp['signac_args'], list):
                    signac_args.append(job.sp['signac_args'])

                project = signac.get_project(root=job.sp['signac_project'],
                                             search=True)
                for arg in signac_args:
                    if isinstance(arg, dict):
                        _job = list(project.find_jobs(filter=arg))[0]
                        slab_files.append(_job.fn('restart.gsd'))
                        ref_distances.append(_job.doc['ref_distance'] / 10)
                    elif isinstance(arg, str):  # Find job using job ID
                        _job = project.open_job(id=arg)
                        slab_files.append(_job.fn('restart.gsd'))
                        ref_distances.append(_job.doc['ref_distance'] / 10)
            elif job.doc['use_signac'] is False:
                slab_files.append(job.sp.slab_file)
                ref_distances.append(job.sp['reference_distance'])

            system = system.Interface(
                slabs=slab_files,
                ref_distance=ref_distances[0],
                gap=job.sp['interface_gap'],
                weld_axis=job.sp["weld_axis"],
            )

            job.doc['slab_ref_distances'] = system.ref_distance
            shrink_kT = None
            shrink_steps = None
            shrink_period = None

        system.system.save('init.mol2', overwrite=True)
        logging.info("System generated...")
        logging.info("Starting simulation...")

        simulation = simulate.Simulation(
            system,
            r_cut=job.sp["r_cut"],
            tau_kt=job.sp['tau_kt'],
            tau_p=job.sp['tau_p'],
            nlist=job.sp['neighbor_list'],
            dt=job.sp['dt'],
            seed=job.sp['sim_seed'],
            auto_scale=True,
            ref_values=None,
            mode="gpu",
            gsd_write=max([int(job.doc['steps'] / 100), 1]),
            log_write=max([int(job.doc['steps'] / 10000), 1]))

        logging.info("Simulation object generated...")
        job.doc['ref_energy'] = simulation.ref_energy
        job.doc['ref_distance'] = simulation.ref_distance
        job.doc['ref_mass'] = simulation.ref_mass
        job.doc['real_timestep'] = unit_conversions.convert_to_real_time(
            simulation.dt, simulation.ref_energy, simulation.ref_distance,
            simulation.ref_mass)
        job.doc['time_unit'] = 'fs'
        job.doc['steps_per_frame'] = simulation.gsd_write
        job.doc['steps_per_log'] = simulation.log_write

        if job.sp['procedure'] == "quench":
            job.doc['T_SI'] = unit_conversions.kelvin_from_reduced(
                job.sp['kT_quench'], simulation.ref_energy)
            job.doc['T_unit'] = 'K'
            logging.info("Beginning quench simulation...")
            simulation.quench(kT=job.sp['kT_quench'],
                              pressure=job.sp['pressure'],
                              n_steps=job.sp['n_steps'],
                              shrink_kT=shrink_kT,
                              shrink_steps=shrink_steps,
                              wall_axis=job.sp['walls'],
                              shrink_period=shrink_period)

        elif job.sp['procedure'] == "anneal":
            logging.info("Beginning anneal simulation...")
            if not job.sp['schedule']:
                kT_list = np.linspace(
                    job.sp['kT_anneal'][0],
                    job.sp['kT_anneal'][1],
                    len(job.sp['anneal_sequence']),
                )
                kT_SI = [
                    unit_conversions.kelvin_from_reduced(
                        kT, simulation.ref_energy) for kT in kT_list
                ]
                job.doc['T_SI'] = kT_SI
                job.doc['T_unit'] = 'K'

            simulation.anneal(kT_init=job.sp['kT_anneal'][0],
                              kT_final=job.sp['kT_anneal'][1],
                              pressure=job.sp['pressure'],
                              step_sequence=job.sp['anneal_sequence'],
                              schedule=job.sp['schedule'],
                              shrink_kT=shrink_kT,
                              shrink_steps=shrink_steps,
                              wall_axis=job.sp['walls'],
                              shrink_period=shrink_period)
Ejemplo n.º 10
0
 def test_slabs_anneal(self, test_slab):
     simulation = simulate.Simulation(test_slab, dt=0.0001, mode="cpu")
     simulation.anneal(kT_init=4,
                       kT_final=2,
                       step_sequence=[1e3, 1e3, 1e3],
                       walls=True)
Ejemplo n.º 11
0
 def test_slabs_quench(self, test_slab):
     simulation = simulate.Simulation(test_slab, dt=0.0001, mode="cpu")
     simulation.quench(kT=2, n_steps=1e3, walls=True)