def test_hydrogen_remove_gaff(): p3ht = Compound("c1cscc1CCCCCC") p3ht_Hs = [h for h in p3ht.particles_by_element("H")] packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm**3, remove_hydrogen_atoms=True, ) system = packer.pack() assert "H" not in [a.name for a in system.atoms] assert p3ht.n_particles * 2 - len(system.atoms) == len(p3ht_Hs) * 2
def test_hydrogen_removal(compound_name): comp = Compound(COMPOUND[compound_name]) packer = Pack( comp, ff=FORCEFIELD["gaff-custom"], n_compounds=2, density=0.1 * u.g / u.cm**3, remove_hydrogen_atoms=True, ) system = packer.pack() assert 1 not in [a.atomic_number for a in system.atoms] assert len(system.atoms) != comp.n_particles * 2
def test_simple_sim(self, compound_name): compound = Compound(COMPOUND[compound_name]) packer = Pack(compound, n_compounds=2, density=0.01 * u.g / u.cm**3) system = packer.pack() my_sim = Simulation( system, kT=3.0, gsd_write=1e2, log_write=1e2, e_factor=1, n_steps=3e3, mode="cpu", shrink_steps=1e3, target_length=packer.L, ) my_sim.run()
def test_bad_temps_raises(self): p3ht = Compound("c1cscc1CCCCCC") packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm ** 3, ) system = packer.pack() with pytest.raises(AssertionError): my_sim = Simulation( system, kT=[3.0, 4.0], tau=[1.0], n_steps=[1e3], mode="cpu", )
def test_typed_gaff_raises(self): p3ht = Compound(COMPOUND["P3HT-16-gaff"]) with pytest.raises(NotImplementedError): packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm**3, )
def test_smiles_opvgaff_raises(self): p3ht = Compound("c1cscc1CCCCCC") with pytest.raises(NotImplementedError): packer = Pack( p3ht, ff=FORCEFIELD["gaff-custom"], n_compounds=2, density=0.01 * u.g / u.cm**3, )
def test_temps_ramp(self): p3ht = Compound("c1cscc1CCCCCC") packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm ** 3, ) system = packer.pack() my_sim = Simulation( system, kT=[3.0, 4.0], tau=[1.0, 1.0], n_steps=[1e3, 1e3], shrink_steps=1e3, target_length=packer.L, mode="cpu", )
def test_hydrogen_removal(): pcbm = Compound(COMPOUND["PCBM-gaff"]) packer = Pack( pcbm, ff=FORCEFIELD["gaff-custom"], n_compounds=2, density=0.1 * u.g / u.cm**3, remove_hydrogen_atoms=True, ) packer._remove_hydrogen() for atom in packer.compound[0].particles(): assert atom.name not in [ "_hc", "_ha", "_h1", "_h4", ], "Hydrogen found in system!"
def test_gaff_noH_raises(self): p3ht = Compound("c1cscc1CCCCCC") with pytest.raises(NotImplementedError): packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm**3, remove_hydrogen_atoms=True, )
def test_smiles_gaff(self): p3ht = Compound("c1cscc1CCCCCC") packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm**3, ) system = packer.pack() my_sim = Simulation( system, kT=3.0, gsd_write=1e2, log_write=1e2, e_factor=1, n_steps=3e3, mode="cpu", shrink_steps=1e3, target_length=packer.L, )
def test_hydrogen_removal_and_sim(): pcbm = Compound(COMPOUND["PCBM-gaff"]) packer = Pack( pcbm, ff=FORCEFIELD["gaff-custom"], n_compounds=2, density=0.1 * u.g / u.cm**3, remove_hydrogen_atoms=True, ) system = packer.pack() my_sim = Simulation( system, kT=[3.0], tau=[1.0], n_steps=[1e3], gsd_write=1e2, log_write=1e2, mode="cpu", shrink_steps=1e3, ) my_sim.run()
def test_nlist(self): p3ht = Compound("c1cscc1CCCCCC") packer = Pack( p3ht, ff=FORCEFIELD["gaff"], n_compounds=2, density=0.01 * u.g / u.cm ** 3, ) system = packer.pack() my_sim = Simulation( system, kT=[3.0], tau=[1.0], n_steps=[1e3], gsd_write=1e2, log_write=1e2, mode="cpu", shrink_steps=1e3, target_length=packer.L, nlist="tree", )
def test_mixture(): pcbm = Compound(COMPOUND["PCBM-gaff"]) p3ht = Compound(COMPOUND["P3HT-gaff"]) packer = Pack( [pcbm, p3ht], ff=FORCEFIELD["gaff-custom"], n_compounds=[2, 3], density=0.01 * u.g / u.cm**3, ) system = packer.pack() my_sim = Simulation( system, kT=[3.0], tau=[1.0], n_steps=[1e3], gsd_write=1e2, log_write=1e2, mode="cpu", shrink_steps=1e3, ) my_sim.run()
def test_no_units(): pcbm = Compound(COMPOUND["PCBM-gaff"]) with pytest.raises(TypeError): packer = Pack(pcbm, n_compounds=2, density=2)
def test_bad_units(): pcbm = Compound(COMPOUND["PCBM-gaff"]) with pytest.raises(UnitConversionError): packer = Pack(pcbm, n_compounds=2, density=2 * u.m)
def sample(job): import glob import warnings import unyt as u from planckton.sim import Simulation from planckton.init import Compound, Pack from planckton.utils import units from planckton.forcefields import FORCEFIELD with job: inputs = [get_paths(i, job) for i in job.sp.input] with warnings.catch_warnings(): warnings.simplefilter("ignore") compound = [Compound(i) for i in inputs] packer = Pack( compound, ff=FORCEFIELD[job.sp.forcefield], n_compounds=list(job.sp.n_compounds), density=units.string_to_quantity(job.sp.density), remove_hydrogen_atoms=job.sp.remove_hydrogens, ) system = packer.pack() print(f"Target length should be {packer.L:0.3f}") if job.isfile("restart.gsd"): restart = job.fn("restart.gsd") target_length = None else: restart = None target_length = packer.L total_steps = sum(job.sp.n_steps, job.sp.shrink_steps) my_sim = Simulation(system, kT=job.sp.kT, tau=job.sp.tau, n_steps=job.sp.n_steps, dt=job.sp.dt, e_factor=job.sp.e_factor, r_cut=job.sp.r_cut, gsd_write=max([int(total_steps / 100), 1]), log_write=max([int(total_steps / 10000), 1]), shrink_steps=job.sp.shrink_steps, shrink_kT=job.sp.shrink_kT, shrink_tau=job.sp.shrink_tau, mode=job.sp.mode, target_length=target_length, restart=restart) job.doc["done"] = my_sim.run() ref_distance = my_sim.ref_values.distance * u.Angstrom ref_energy = my_sim.ref_values.energy * u.kcal / u.mol ref_mass = my_sim.ref_values.mass * 0.9999938574 * u.amu job.doc["T_SI"] = [ units.quantity_to_string(units.kelvin_from_reduced(kT, ref_energy)) for kT in job.sp.kT ] job.doc["real_timestep"] = units.quantity_to_string( units.convert_to_real_time(job.sp.dt, ref_mass, ref_distance, ref_energy).to("femtosecond")) job.doc["ref_mass"] = units.quantity_to_string(ref_mass) job.doc["ref_distance"] = units.quantity_to_string(ref_distance) job.doc["ref_energy"] = units.quantity_to_string(ref_energy) outfiles = glob.glob(f"{job.ws}/job*.o") if outfiles: tps, time = get_tps_time(outfiles) job.doc["average_TPS"] = tps job.doc["total_time"] = time