Ejemplo n.º 1
0
def test_write():
    lmp = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp', improper_center=3)
    tmp = os.path.join(tmpdir, 'lmp-out.psf')
    lmp.write(tmp)
    assert filecmp.cmp(tmp, cwd + '/files/baselines/lmp-out.psf')

    zmat = Topology.open(cwd + '/files/Im11.zmat')
    tmp = os.path.join(tmpdir, 'zmat-out.psf')
    zmat.write(tmp)
    assert filecmp.cmp(tmp, cwd + '/files/baselines/zmat-out.psf')
Ejemplo n.º 2
0
def test_write():
    zmat = Topology.open(cwd + '/files/Im11.zmat')
    tmp = os.path.join(tmpdir, 'zmat-out.xyz')
    zmat.write(tmp)
    assert filecmp.cmp(tmp, cwd + '/files/baselines/zmat-out.xyz')

    mol = Molecule.from_smiles('C[n+]1cn(cc1)CCCC[B-](F)(F)F')
    top = Topology([mol])
    tmp = os.path.join(tmpdir, 'smi-out.xyz')
    top.write(tmp)
    filecmp.cmp(tmp, cwd + '/files/baselines/smi-out.xyz')
Ejemplo n.º 3
0
def test_write_swm4():
    ff = ForceField.open(cwd + '/../forcefield/files/SWM4-NDP.zfp')
    mol = Topology.open(cwd + '/files/TIP3P.zmat').molecules[0]
    mol.generate_virtual_sites(ff)
    mol.generate_drude_particles(ff)
    mol.assign_charge_from_ff(ff)

    top = Topology([mol], numbers=[10])
    tmp = os.path.join(tmpdir, 'swm4-out.psf')
    top.write(tmp)

    assert filecmp.cmp(tmp, cwd + '/files/baselines/swm4-out.psf')
Ejemplo n.º 4
0
def test_improper():
    lmp = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp')
    assert lmp.n_improper == 10
    improper = lmp.impropers[0]
    assert improper.atom1.id + 1 == 32
    assert improper.atom2.id + 1 == 34
    assert improper.atom3.id + 1 == 31
    assert improper.atom4.id + 1 == 35

    lmp = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp', improper_center=3)
    improper = lmp.impropers[0]
    assert improper.atom1.id + 1 == 31
    assert improper.atom2.id + 1 == 32
    assert improper.atom3.id + 1 == 34
    assert improper.atom4.id + 1 == 35
Ejemplo n.º 5
0
def test_typing():
    im61 = Molecule.from_smiles('C[n+]1cn(cc1)CCCCCC')
    im2eben = Molecule.from_smiles('C[n+]1cn(cc1)CCc1ccccc1')
    im2bben = Molecule.from_smiles('C[n+]1cn(cc1)CCCc1ccccc1')
    dca = Molecule.from_smiles('N#C[N-]C#N')
    fsi = Molecule.from_smiles('FS(=O)(=O)[N-]S(=O)(=O)F')
    tfsi = Molecule.from_smiles('FC(F)(F)S(=O)(=O)[N-]S(=O)(=O)C(F)(F)(F)')
    top = Topology([im61, im2eben, im2bben, dca, fsi, tfsi])

    typer = ZftTyper(cwd + '/files/CLP-define.zft')
    typer.type(top)

    assert [atom.type for atom in im61.atoms] == (
            ['C1', 'NA', 'CR', 'NA', 'CW', 'CW', 'C1', 'C2', 'CS', 'CS', 'CS', 'CT']
            + ['H1', 'H1', 'H1', 'HCR', 'HCW', 'HCW'] + ['H1', 'H1'] + ['HC'] * 11)
    assert [atom.type for atom in im2eben.atoms] == (
            ['C1', 'NA', 'CR', 'NA', 'CW', 'CW', 'C_4H2_NA',
             'C_4H2_CA', 'CAT', 'CAO', 'CAM', 'CAP', 'CAM', 'CAO']
            + ['H1', 'H1', 'H1', 'HCR', 'HCW', 'HCW']
            + ['H1', 'H1', 'HT', 'HT'] + ['HAT'] * 5)
    assert [atom.type for atom in dca.atoms] == ['NZA', 'CZA', 'N3A', 'CZA', 'NZA']
    assert [atom.type for atom in fsi.atoms] == (
        ['FSI', 'SBT', 'OBT', 'OBT', 'NBT', 'SBT', 'OBT', 'OBT', 'FSI'])
    assert [atom.type for atom in tfsi.atoms] == (
        ['F1', 'CBT', 'F1', 'F1', 'SBT', 'OBT', 'OBT', 'NBT', 'SBT', 'OBT', 'OBT',
         'CBT', 'F1', 'F1', 'F1'])
Ejemplo n.º 6
0
def test_read_swm4():
    psf = Topology.open(cwd + '/files/9-SWM4.psf')
    assert psf.n_molecule == 9

    mol = psf.molecules[-1]
    assert mol.n_atom == 5

    assert not mol.atoms[0].is_drude
    assert mol.atoms[1].is_drude
    assert not mol.atoms[2].is_drude
    assert not mol.atoms[3].is_drude
    assert not mol.atoms[4].is_drude

    atom = mol.atoms[0]
    assert atom.alpha == 0.0009782
    assert atom.thole == 2.6

    assert mol.atoms[0].virtual_site is None
    assert mol.atoms[1].virtual_site is None
    assert mol.atoms[2].virtual_site is None
    assert mol.atoms[3].virtual_site is None
    assert mol.atoms[4].virtual_site is not None

    vsite = mol.atoms[-1].virtual_site
    assert type(vsite) is TIP4PSite
    assert vsite.parents[0] is mol.atoms[0]
    assert vsite.parents[1] is mol.atoms[2]
    assert vsite.parents[2] is mol.atoms[3]
    assert vsite.parameters == [0.024034]
Ejemplo n.º 7
0
def test_typing():
    im2eben = Molecule.from_smiles('C[n+]1cn(cc1)CCc1ccccc1')
    fsi = Molecule.from_smiles('FS(=O)(=O)[N-]S(=O)(=O)F')
    top = Topology([im2eben, fsi])

    if os.path.exists(r'D:\Projects\DFF\Developing'):
        dff_root = pathlib.Path(r'D:\Projects\DFF\Developing')
    else:
        path = shutil.which('dffjob.exe')
        if path is not None:
            dff_root = pathlib.Path(path).parent.parent
        else:
            print('DFF not found')
            assert 0

    dff = DFF(dff_root)
    typer = DffTyper(dff, dff_root.joinpath('database/TEAMFF.ref/IL/IL.ext'))
    typer.type(top)

    assert [atom.type for atom in im2eben.atoms] == ([
        'c_4nph3', 'n_35+da', 'c_35an2', 'n_35+da', 'c_35an', 'c_35an',
        'c_4np', 'c_4h2', 'c_3ac', 'c_3a', 'c_3a', 'c_3a', 'c_3a', 'c_3a'
    ] + ['h_1'] * 15)
    assert [atom.type for atom in fsi.atoms] == ([
        'f_1', 's_4o', 'o_1', 'o_1', 'n_2-', 's_4o', 'o_1', 'o_1', 'f_1'
    ])
Ejemplo n.º 8
0
def read_mols(files, ff):
    mols = []
    for f in files:
        mol = Topology.open(f).molecules[0]
        if f.endswith("xyz"):
            mol.guess_connectivity_from_ff(ff)
        mols.append(mol)
    return mols
Ejemplo n.º 9
0
def test_transfer_bonded_terms():
    top = Topology.open(cwd + '/../topology/files/c_3oh.msd')
    ff = ForceField.open(cwd + '/../topology/files/c_3oh.ppf')
    top.assign_charge_from_ff(ff, transfer_bci_terms=True)
    system = System(top, ff, transfer_bonded_terms=True)
    angle = next(a for a in system.topology.angles if a.name == 'C2-C3-H8')
    assert ff.get_eqt_for_angle(angle) == ('c_3', 'c_3o', 'h_1')
    aterm = system.angle_terms[id(angle)]
    assert aterm.name == 'c_3,c_3,h_1'
Ejemplo n.º 10
0
def test_guess_connectivity():
    top = Topology.open(cwd + '/files/MoS2-13x8-layer1.xyz')
    top.cell.set_box([4.109, 4.380, 1.230])
    ff = ForceField.open(cwd + '/files/MoS2.ff')
    top.guess_connectivity_from_ff(ff, angle_tolerance=15, pbc='xy')
    assert top.n_bond == 1248
    assert top.n_angle == 3120
    assert top.n_dihedral == 0
    assert top.n_improper == 0
Ejemplo n.º 11
0
def test_write():
    top = Topology.open(cwd + '/files/100-SPCE.psf')
    xtc = Trajectory.open(cwd + '/files/100-SPCE.xtc')
    tmp = os.path.join(tempdir, 'xtc-out.xyz')
    xyz = Trajectory.open(tmp, 'w')
    for i in range(xtc.n_frame):
        frame = xtc.read_frame(i)
        xyz.write_frame(frame, top, subset=list(range(150, 300)))
    xyz.close()
    filecmp.cmp(tmp, cwd + '/files/baselines/xtc-out.xyz')
Ejemplo n.º 12
0
def test_connectivity():
    ethane = Topology.open(cwd + '/files/CH3NH2.pdb').molecules[0]
    assert pytest.approx(ethane.bonds[0].evaluate(), abs=1E-4) == 0.1070
    assert pytest.approx(ethane.angles[0].evaluate(),
                         abs=1E-4) == 109.5278 / 180 * math.pi
    assert pytest.approx(ethane.dihedrals[0].evaluate(),
                         abs=1E-4) == 60.0301 / 180 * math.pi
    assert pytest.approx(ethane.dihedrals[-1].evaluate(),
                         abs=1E-4) == -60.0159 / 180 * math.pi
    assert pytest.approx(ethane.impropers[0].evaluate(),
                         abs=1E-4) == -33.0905 / 180 * math.pi
Ejemplo n.º 13
0
def test_charmm():
    ff = ForceField.open(cwd + '/files/10-benzene.ppf')
    top = Topology.open(cwd + '/files/10-benzene.lmp', improper_center=3)
    top.assign_charge_from_ff(ff)
    system = System(top, ff)
    tmppdb = os.path.join(tmpdir, 'conf.pdb')
    tmppsf = os.path.join(tmpdir, 'topol.psf')
    tmpprm = os.path.join(tmpdir, 'ff.prm')
    system.export_charmm(pdb_out=tmppdb, psf_out=tmppsf, prm_out=tmpprm)
    assert filecmp.cmp(tmppdb, cwd + '/files/baselines/conf.pdb')
    assert filecmp.cmp(tmppsf, cwd + '/files/baselines/topol.psf')
    assert filecmp.cmp(tmpprm, cwd + '/files/baselines/ff.prm')
Ejemplo n.º 14
0
def test_gmx():
    ff = ForceField.open(cwd + '/files/10-benzene.ppf')
    top = Topology.open(cwd + '/files/10-benzene.lmp', improper_center=3)
    top.assign_charge_from_ff(ff)
    system = System(top, ff)
    tmpgro = os.path.join(tmpdir, 'conf.gro')
    tmptop = os.path.join(tmpdir, 'topol.top')
    tmpmdp = os.path.join(tmpdir, 'grompp.mdp')
    system.export_gromacs(gro_out=tmpgro, top_out=tmptop, mdp_out=tmpmdp)
    assert filecmp.cmp(tmpgro, cwd + '/files/baselines/conf.gro')
    assert filecmp.cmp(tmptop, cwd + '/files/baselines/topol.top')
    assert filecmp.cmp(tmpmdp, cwd + '/files/baselines/grompp.mdp')
Ejemplo n.º 15
0
def test_team_vacuum():
    ff = ForceField.open(cwd + '/files/10-benzene.ppf')
    top = Topology.open(cwd + '/files/10-benzene.lmp', improper_center=3)
    top.assign_charge_from_ff(ff)
    system = System(top, ff, cell=UnitCell([0, 0, 0]))

    context = mm.Context(system.to_omm_system(), *get_omm_integrator_platform())
    context.setPositions(top.positions)

    print_energy_terms(context)

    pe = context.getState(getEnergy=True).getPotentialEnergy().value_in_unit(kcal_mol)
    assert pytest.approx(pe, rel=0.001) == 490.8
Ejemplo n.º 16
0
def test_lmp_drude():
    ff = ForceField.open(cwd + '/../forcefield/files/CLP.ff',
                         cwd + '/../forcefield/files/CLPol-alpha.ff')
    top = Topology.open(cwd + '/files/5-Im21-BF4-drude.lmp')
    top.generate_angle_dihedral_improper()
    top.generate_drude_particles(ff)
    top.assign_charge_from_ff(ff)
    system = System(top, ff)
    tmpdata = os.path.join(tmpdir, 'data-drude.lmp')
    tmpin = os.path.join(tmpdir, 'in-drude.lmp')
    system.export_lammps(data_out=tmpdata, in_out=tmpin)
    assert filecmp.cmp(tmpdata, cwd + '/files/baselines/data-drude.lmp')
    assert filecmp.cmp(tmpin, cwd + '/files/baselines/in-drude.lmp')
Ejemplo n.º 17
0
def test_eqt_vdw():
    ff = ForceField.open(cwd + '/files/c_3ad.ppf')
    top = Topology.open(cwd + '/files/c_3ad.msd')
    top.assign_charge_from_ff(ff)
    system = System(top, ff)

    context = mm.Context(system.to_omm_system(), *get_omm_integrator_platform())
    context.setPositions(top.positions)

    print_energy_terms(context)

    pe = context.getState(getEnergy=True).getPotentialEnergy().value_in_unit(kcal_mol)
    assert pytest.approx(pe, rel=0.001) == 46.55
Ejemplo n.º 18
0
def test_assign_charge():
    top = Topology.open(cwd + '/files/c_3oh.msd')
    ff = ForceField.open(cwd + '/files/c_3oh.ppf')
    top.assign_charge_from_ff(ff)
    charges = [atom.charge for atom in top.atoms]
    assert pytest.approx(charges, abs=1E-6) == [
        -0.32, -0.16, 0.4791, -0.45, 0.16, 0.16, 0.16, -0.0291
    ]

    top.assign_charge_from_ff(ff, transfer_bci_terms=True)
    charges = [atom.charge for atom in top.atoms]
    assert pytest.approx(charges, abs=1E-6) == [
        -0.32, -0.1954, 0.5145, -0.45, 0.16, 0.16, 0.16, -0.0291
    ]
Ejemplo n.º 19
0
def test_read():
    xyz = Topology.open(cwd + '/files/urea.xyz')
    assert xyz.n_atom == 8
    assert xyz.cell.volume == 0

    mol = xyz.molecules[0]
    assert mol.name == 'urea'

    atom = xyz.atoms[-1]
    assert atom.name == 'H8'
    assert atom.type == 'HU'
    assert atom.symbol == 'H'
    assert pytest.approx(atom.position, abs=1E-6) == [-0.194866, -0.115100, -0.158814]
    assert atom.has_position
Ejemplo n.º 20
0
def test_sdk():
    ff = ForceField.open(cwd + '/../forcefield/files/SPICA_v1.zfp')
    top = Topology.open(cwd + '/files/10-SDS-20-W.lmp')
    for atom in top.atoms:
        atom.charge /= 80 ** 0.5
    system = System(top, ff)

    context = mm.Context(system.to_omm_system(), *get_omm_integrator_platform())
    context.setPositions(top.positions)

    print_energy_terms(context)

    pe = context.getState(getEnergy=True).getPotentialEnergy().value_in_unit(kcal_mol)
    assert pytest.approx(pe, rel=0.001) == 186.0
Ejemplo n.º 21
0
def test_read():
    pdb = Topology.open(cwd + '/files/test.pdb')
    assert pdb.n_atom == 16
    assert pytest.approx(pdb.cell.volume, abs=1E-6) == 0.06

    mol = pdb.molecules[0]
    assert mol.name == 'c1c1'

    atom = pdb.atoms[-1]
    assert atom.name == 'H16'
    assert atom.type == ''
    assert atom.symbol == 'H'
    assert pytest.approx(atom.position, abs=1E-6) == [0.3369, 0.2249, -0.0890]
    assert atom.has_position
Ejemplo n.º 22
0
def test_vdw_shift():
    ff = ForceField.open(cwd + '/files/10-benzene.ppf')
    ff.vdw_long_range = ff.VDW_LONGRANGE_SHIFT

    top = Topology.open(cwd + '/files/10-benzene.lmp', improper_center=3)
    # top.assign_charge_from_ff(ff)
    system = System(top, ff)

    context = mm.Context(system.to_omm_system(), *get_omm_integrator_platform())
    context.setPositions(top.positions)

    print_energy_terms(context)

    pe = context.getState(getEnergy=True).getPotentialEnergy().value_in_unit(kcal_mol)
    assert pytest.approx(pe, rel=0.001) == 494.3
Ejemplo n.º 23
0
def test_scale():
    if os.path.exists(
            r'D:\Projects\DFF\Developing\bin32w\Packmol\packmol.exe'):
        path = r'D:\Projects\DFF\Developing\bin32w\Packmol\packmol.exe'
    else:
        path = shutil.which('packmol')
        if path is None:
            print('Packmol not found')
            assert 0

    packmol = Packmol(path)
    top = Topology.open(cwd + '/files/Im11.zmat')
    top.cell.set_box([3, 3, 3])
    top.scale_with_packmol(10, packmol)
    top.write(cwd + '/files/packmol.pdb')
Ejemplo n.º 24
0
def test_gmx_drude():
    ff = ForceField.open(cwd + '/../forcefield/files/CLP.ff',
                         cwd + '/../forcefield/files/CLPol-alpha.ff')
    top = Topology.open(cwd + '/files/5-Im21-BF4-drude.lmp')
    top.generate_angle_dihedral_improper()
    top.generate_drude_particles(ff)
    top.assign_charge_from_ff(ff)
    system = System(top, ff)
    tmpgro = os.path.join(tmpdir, 'conf-drude.gro')
    tmptop = os.path.join(tmpdir, 'topol-drude.top')
    tmpmdp = os.path.join(tmpdir, 'grompp-drude.mdp')
    system.export_gromacs(gro_out=tmpgro, top_out=tmptop, mdp_out=tmpmdp)
    assert filecmp.cmp(tmpgro, cwd + '/files/baselines/conf-drude.gro')
    assert filecmp.cmp(tmptop, cwd + '/files/baselines/topol-drude.top')
    assert filecmp.cmp(tmpmdp, cwd + '/files/baselines/grompp-drude.mdp')
Ejemplo n.º 25
0
def test_tip4p():
    top = Topology.open(os.path.join(cwd, 'files/TIP3P.zmat'))
    mol = top.molecules[0]

    ff = ForceField.open(os.path.join(cwd, '../forcefield/files/TIP4P.zfp'))
    mol.generate_virtual_sites(ff)
    mol.assign_charge_from_ff(ff)

    avsite = top.atoms[-1]
    assert avsite.name == 'VS1'
    assert avsite.type == 'MW'
    assert pytest.approx(avsite.position,
                         abs=1E-6) == [0.0091824, -0.011861, 0.]

    assert pytest.approx([atom.charge for atom in top.atoms],
                         abs=1E-6) == [0, 0.52, 0.52, -1.04]
Ejemplo n.º 26
0
def test_drude():
    ff = ForceField.open(cwd + '/../forcefield/files/CLP.ff', cwd + '/../forcefield/files/CLPol-alpha.ff')
    top = Topology.open(cwd + '/files/5-Im21-BF4-drude.lmp')
    top.generate_angle_dihedral_improper()
    # top.remove_drude_particles()
    # top.generate_drude_particles(ff)
    top.assign_charge_from_ff(ff)

    system = System(top, ff)

    context = mm.Context(system.to_omm_system(), *get_omm_integrator_platform())
    context.setPositions(top.positions)

    print_energy_terms(context)

    pe = context.getState(getEnergy=True).getPotentialEnergy().value_in_unit(kcal_mol)
    assert pytest.approx(pe, rel=0.001) == 100.8
Ejemplo n.º 27
0
def test_read():
    zmat = Topology.open(cwd + '/files/Im11.zmat')
    assert zmat.n_atom == 16
    assert zmat.n_bond == 16
    assert zmat.n_angle == 27
    assert zmat.n_dihedral == 32
    assert zmat.n_improper == 5
    assert zmat.cell.volume == 0

    atom = zmat.atoms[0]
    assert all(atom.position == [0., 0., 0.])
    assert atom.name == 'N1'
    assert atom.type == 'NA'
    atom = zmat.atoms[-1]
    assert pytest.approx(atom.position, abs=1E-4) == [0.3369, 0.2250, -0.0890]
    assert atom.name == 'H16'
    assert atom.type == 'H1'
Ejemplo n.º 28
0
def test_compress():
    top = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp', improper_center=3)
    molecules = top.molecules
    for mol in molecules[4:]:
        for atom in mol.atoms:
            atom.charge *= 2

    top = Topology.open(cwd + '/files/Im11.zmat')
    molecules += top.molecules

    top = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp', improper_center=3)
    molecules += top.molecules

    top = Topology.open(cwd + '/files/Im11.zmat')
    molecules += top.molecules

    top = Topology()
    top.update_molecules(molecules)
    mols_unique = top.get_unique_molecules()
    for mol, count in mols_unique.items():
        print(str(mol), count)

    assert list(mols_unique.values()) == [4, 6, 5, 1, 10, 5, 1]
Ejemplo n.º 29
0
def test_read():
    lmp = Topology.open(cwd + '/files/10-H2O-5-C3H6.lmp')
    assert lmp.n_atom == 75
    assert lmp.n_molecule == 15
    assert lmp.is_drude == False
    assert lmp.cell.is_rectangular
    assert pytest.approx(lmp.cell.lengths,
                         abs=1E-6) == [3.18888, 3.18888, 3.18888]

    atom = lmp.atoms[0]
    assert atom.id == 0
    assert atom.molecule.id == 0
    assert atom.molecule.name == 'WAT'
    assert atom.type == 'o_2w'
    assert atom.name == 'O1'
    assert atom.charge == -0.8476
    assert atom.mass == 15.9994

    atom = lmp.atoms[-1]
    assert atom.id == 74
    assert atom.molecule.id == 14
    assert atom.molecule.name == 'C3H6'
    assert atom.type == 'h_1'
    assert atom.name == 'H9'
    assert atom.charge == 0.06
    assert atom.mass == 1.0079

    mol = lmp.molecules[0]
    assert mol.id == 0
    assert mol.name == 'WAT'

    mol = lmp.molecules[-1]
    assert mol.id == 14
    assert mol.name == 'C3H6'

    assert lmp.has_position
    atom = lmp.atoms[0]
    assert pytest.approx(atom.position, abs=1E-6) == [2.4257, 0.3594, 0.3218]
    atom = lmp.atoms[-1]
    assert pytest.approx(atom.position, abs=1E-6) == [1.6725, 2.1756, 0.5918]
Ejemplo n.º 30
0
def test_read():
    psf = Topology.open(cwd + '/files/10-H2O-5-C3H6.psf')
    assert psf.is_drude == False
    assert psf.n_atom == 75
    assert psf.n_molecule == 15
    assert psf.n_bond == 60
    assert psf.n_angle == 70
    assert psf.n_dihedral == 50
    assert psf.n_improper == 10
    assert psf.cell.volume == 0

    assert psf.bonds[-1].atom1.name == 'C69'
    assert psf.angles[-1].atom2.name == 'C69'
    assert psf.dihedrals[-1].atom4.name == 'H75'
    assert psf.impropers[-1].atom1.type == 'c_3h'

    atom = psf.atoms[0]
    assert atom.id == 0
    assert atom.molecule.id == 0
    assert atom.type == 'o_2w'
    assert atom.name == 'O1'
    assert atom.charge == -0.8476
    assert atom.mass == 15.9994

    atom = psf.atoms[-1]
    assert atom.id == 74
    assert atom.molecule.id == 14
    assert atom.type == 'h_1'
    assert atom.name == 'H75'
    assert atom.charge == 0.06
    assert atom.mass == 1.00794

    mol = psf.molecules[0]
    assert mol.id == 0
    assert mol.name == 'WAT'

    mol = psf.molecules[-1]
    assert mol.id == 14
    assert mol.name == 'C3H'