Esempio n. 1
0
def test_opt_gamess():
    """
    Test Optimization in Gamess using methanol in water.
    """
    methanol = Molecule('test/test_files/ion_methanol.xyz')
    methanol.properties['symmetry'] = 'Cs'

    s = Settings()
    s.specific.gamess.contrl.nzvar = 12
    s.specific.gamess.system.timlim = 2
    s.specific.gamess.system.mwords = 2
    s.specific.gamess.pcm.solvnt = 'water'
    s.specific.gamess.basis.gbasis = 'sto'
    s.specific.gamess.basis.ngauss = 3
    s.specific.gamess.guess.guess = 'huckel'
    s.specific.gamess.stapt.optol = '1d-5'
    s.specific.gamess.zmat["izmat(1)"] = "1,1,2,  1,2,3,  1,3,4,  1,3,5,  1,3,6, \n"\
                                         "2,1,2,3,  2,2,3,4,  2,2,3,5,  2,2,3,6, \n"\
                                         "3,1,2,3,4,  3,1,2,3,5,  3,1,2,3,6"

    inp = templates.geometry.overlay(s)
    methanol_geometry = gamess(inp, methanol, work_dir='/tmp')

    mol_opt = run(methanol_geometry.molecule)

    coords = concat([a.coords for a in mol_opt.atoms])

    expected_coords = [-0.9956983464, 0.9204754677, -0.0002616586, -0.72585581,
                       -0.0802380791, 2.18166e-05, 0.741292161, 0.0371204735,
                       -1.69738e-05, 1.1448441964, 0.5632291664, -0.9026112278,
                       1.1448447102, 0.562978981, 0.9027182521,
                       1.1454516521, -0.9993402516, 1.04943e-05]

    assert abs(sum(zipWith(operator.sub)(coords)(expected_coords))) < 1e-7
Esempio n. 2
0
def parse_molecule_traj(file_traj):
    """
    Read Molecules from the *.traj file.
    """
    mols = manyXYZ(file_traj)
    # Last geometry corresponds to the optimized structure
    opt_mol = mols[-1]

    plams_mol = Molecule()
    for at in opt_mol:
        symb = at.symbol
        cs = at.xyz
        plams_mol.add_atom(Atom(symbol=symb, coords=tuple(cs)))

    return plams_mol
Esempio n. 3
0
def test_opt_orca():
    """
    Test Orca input generation and run functions.
    """
    h2o = Molecule('test/test_files/h2o.xyz', 'xyz', charge=0, multiplicity=1)

    h2o_geometry = dftb(templates.geometry, h2o)

    s = Settings()
    # generic keyword "basis" must be present in the generic dictionary
    s.basis = "sto_dzp"
    # "specific" allows the user to apply specific keywords for a
    # package that are not in a generic dictionary
    # s.specific.adf.basis.core = "large"

    r = templates.singlepoint.overlay(s)
    h2o_singlepoint = orca(r, h2o_geometry.molecule)

    dipole = h2o_singlepoint.dipole

    final_result = run(dipole, n_processes=1)

    expected_dipole = [0.82409, 0.1933, -0.08316]
    diff = sqrt(sum((x - y)**2 for x, y in zip(final_result, expected_dipole)))
    print("Expected dipole computed with Orca 3.0.3 is:", expected_dipole)
    print("Actual dipole is:", final_result)

    assert diff < 1e-2
Esempio n. 4
0
def test_freq():
    """
    Do some constraint optimizations then launch a freq calc.
    """

    mol = Molecule("test/test_files/ethene.xyz", "xyz")
    geo_opt = dftb(templates.geometry, mol)
    freq_calc = dftb(templates.freq, geo_opt.molecule, job_name="freq")
    r = run(freq_calc)
    assert int(r.frequencies[0]) == 831
    assert len(r.frequencies) == 12
Esempio n. 5
0
def string_array_to_molecule(parser_fun, file_name):
    """
    Convert a Numpy string array like:

    [['C', '-1.487460', '-0.028670', '-0.000060'],
    ['O', '0.376340', '0.028670', '-0.000060'],
    ['H', '-1.818910', '-1.067060', '-0.000060'],
    ['H', '-1.866470', '0.473700', '0.889930'],
    ['H', '-1.866470', '0.473700', '-0.890040'],
    ['H', '0.756720', '-0.950010', '-0.000060']]

    To a plams ``Molecule``.
    """
    string_array_to_float = np.vectorize(float)
    mols = parse_file(parser_fun, file_name).asList()
    last_mol = np.array(mols[-1])
    elems = last_mol[:, 0]
    coords = string_array_to_float(last_mol[:, 1:])
    plams_mol = Molecule()
    for e, c in zip(elems, coords):
        plams_mol.add_atom(Atom(symbol=e, coords=tuple(c)))

    return plams_mol
Esempio n. 6
0
def fragmentsjob(settings, mol, *frozen_frags):
    mol_tot = Molecule()
    frag_settings = Settings()
    for i, frag in enumerate(frozen_frags):
        frag_id = 'frag' + str(i+1)
        for m in frag.mol_list:
            for a in m:
                a.fragment = frag_id
            mol_tot += m
        path = frag.result.kf.path + ' type=FDE'
        frag_settings.specific.adf.fragments[frag_id] = path
        frag_settings.specific.adf.fde.PW91k = ""
    mol_tot += mol

    return adf(settings.overlay(frag_settings), mol_tot, job_name = "fde")
Esempio n. 7
0
def test_freq_ethylene():
    """
    Run a methanol optimization and retrieve the optimized geom.
    """
    ethylene = Molecule('test/test_files/ethylene.xyz')

    s = Settings()
    s.specific.orca.main = "freq"
    s.specific.orca.basis.basis = 'sto_sz'
    s.specific.orca.method.functional = 'lda'
    s.specific.orca.method.method = 'dft'

    freq = orca(s, ethylene)

    mol = run(freq.molecule)
    print(mol)

    assert False
Esempio n. 8
0
def rdkit2plams(rdkit_mol):
    """
    Translate an RDKit molecule into a PLAMS molecule type
    """
    plams_mol = Molecule()
    total_charge = 0
    Chem.Kekulize(rdkit_mol)
    conf = rdkit_mol.GetConformer()
    for atom in rdkit_mol.GetAtoms():
        pos = conf.GetAtomPosition(atom.GetIdx())
        ch = atom.GetFormalCharge()
        plams_mol.add_atom(
            Atom(atom.GetAtomicNum(), coords=(pos.x, pos.y, pos.z), charge=ch))
        total_charge += ch
    for bond in rdkit_mol.GetBonds():
        at1 = plams_mol.atoms[bond.GetBeginAtomIdx()]
        at2 = plams_mol.atoms[bond.GetEndAtomIdx()]
        plams_mol.add_bond(Bond(at1, at2, bond.GetBondTypeAsDouble()))
    plams_mol.charge = total_charge
    for propname in rdkit_mol.GetPropNames():
        plams_mol.properties[propname] = rdkit_mol.GetProp(propname)
    return plams_mol
Esempio n. 9
0
def add_fragments(job1, job2, switch=False):
    print("path1: ", job1.kf.path)
    print("path2: ", job2.kf.path)
    mol_1 = job1.molecule.copy()
    mol_2 = job2.molecule.copy()
    for a in mol_1:
        if not switch:
            a.fragment = 'frag1'
        else:
            a.fragment = 'frag2'
    for a in mol_2:
        if not switch:
            a.fragment = 'frag2'
        else:
            a.fragment = 'frag1'
    m_tot = Molecule()
    if not switch:
        m_tot += mol_1 + mol_2
    else:
        m_tot += mol_2 + mol_1
    return m_tot
Esempio n. 10
0
def test_methanol_opt_orca():
    """
    Run a methanol optimization and retrieve the optimized geom.
    """
    methanol = Molecule('test/test_files/methanol.xyz')

    s = Settings()
    s.specific.orca.main = "RKS B3LYP SVP Opt TightSCF SmallPrint"

    opt = orca(s, methanol)

    mol_opt = run(opt.molecule)

    expected_coords = [
        -1.311116, -0.051535, -0.000062, 0.097548, 0.033890, -0.000077,
        -1.683393, -1.092152, -0.000066, -1.734877, 0.448868, 0.891460,
        -1.734894, 0.448881, -0.891567, 0.460481, -0.857621, -0.000038
    ]

    coords = concat([a.coords for a in mol_opt.atoms])

    assert abs(sum(zipWith(operator.sub)(coords)(expected_coords))) < 1e-7
Esempio n. 11
0
def test_linear_ts():
    """
    compute a first approximation to the TS.
    """
    # Read the Molecule from file
    cnc = Molecule('test/test_files/C-N-C.mol', 'mol')

    # User define Settings
    settings = Settings()
    settings.functional = "pbe"
    settings.basis = "SZ"
    settings.specific.dftb.dftb.scc

    constraint1 = Distance(0, 4)
    constraint2 = Distance(2, 3)

    # scan input
    pes = PES(cnc,
              constraints=[constraint1, constraint2],
              offset=[2.3, 2.3],
              get_current_values=False,
              nsteps=2,
              stepsize=[0.1, 0.1])

    # returns a set of results object containing the output of
    # each point in the scan
    lt = pes.scan([dftb, adf], settings)

    # Gets the object presenting the molecule
    # with the maximum energy calculated from the scan
    apprTS = select_max(lt, "energy")

    # Run the TS optimization, using the default TS template
    ts = run(apprTS)

    expected_energy = -3.219708290363864

    assert abs(ts.energy - expected_energy) < 0.02
Esempio n. 12
0
from qmworks.components import PES_scan, select_max

import plams
# ========== =============


def bond_distance(r1, r2):
    return sqrt(sum((x - y)**2 for x, y in zip(r1, r2)))


# ========== =============

plams.init()

# Read the Molecule from file
cnc = Molecule('C-N-C.mol', 'mol')

# User define Settings
settings = Settings()
settings.functional = "pbe"
settings.basis = "TZ2P"
settings.specific.dftb.dftb.scc

constraint1 = "dist 1 5"
constraint2 = "dist 3 4"

# scan input
scan = {
    'constraint': [constraint1, constraint2],
    'surface': {
        'nsteps': 6,
Esempio n. 13
0
            for a in m:
                a.fragment = frag_id
            mol_tot += m
        path = frag.result.kf.path + ' type=FDE'
        frag_settings.specific.adf.fragments[frag_id] = path
        frag_settings.specific.adf.fde.PW91k = ""
    mol_tot += mol

    return adf(settings.overlay(frag_settings), mol_tot, job_name = "fde")
# ----------------------------------------------------------------


plams.init()

# Read the Molecule from file
m_h2o_1 = Molecule('FDE-H2O-1.xyz')
m_h2o_2 = Molecule('FDE-H2O-2.xyz')
m_mol   = Molecule('FDE-mol.xyz')

m_tot = m_mol + m_h2o_1 + m_h2o_2

print(m_tot)

settings = Settings()
settings.basis = 'SZ'
settings.specific.adf.nosymfit = ''

# Prepare first water molecule
r_h2o_1 = adf(templates.singlepoint.overlay(settings), m_h2o_1, job_name="h2o_1")

# Prepare second water molecule