예제 #1
0
def mopac(mol, lab, level):
    if level == 'Trip':
        mol.set_calculator(
            MOPAC(label=lab, method='PM6 UHF THREADS=1 PRTXYZ TRIPLET'))
    else:
        mol.set_calculator(MOPAC(label=lab, method='PM6  PRTXYZ THREADS=1'))
    return mol
예제 #2
0
def mopacFreq(mol, lab, level):
    if level == 'Trip':
        mol.set_calculator(
            MOPAC(label=lab, method='PM7 FORCE TRIPLET THREADS=1', task=''))
    else:
        mol.set_calculator(
            MOPAC(label=lab, method='PM7 FORCE  THREADS=1', task=''))
    return mol
예제 #3
0
def mopacTS(mol, lab, level):
    if level == 'Trip':
        mol.set_calculator(
            MOPAC(label=lab,
                  method='PM7 TS OPT RECALC=1  THREADS=1 TRIPLET',
                  task=''))
    else:
        mol.set_calculator(
            MOPAC(label=lab, method='PM7 TS OPT RECALC=1  THREADS=1', task=''))
    return mol
예제 #4
0
def mopacIRC1(mol, lab, level):
    if level == 'Trip':
        mol.set_calculator(
            MOPAC(label=lab,
                  method='PM7 IRC=1 X-PRIORITY=0.05 LARGE=5 THREADS=1 TRIPLET',
                  task=''))
    else:
        mol.set_calculator(
            MOPAC(label=lab,
                  method='PM7 IRC=1 X-PRIORITY=0.05 LARGE=5 THREADS=1',
                  task=''))
    return mol
예제 #5
0
파일: mopac.py 프로젝트: puckvg/chemhelp
def get_atomization(method):

    # singlet - 0 unpaired electrons
    # doublet - 1 unpaired electrons
    # triplet - 2 unpaired electrons
    # quartet - 3 unpaired electrons
    # quintet - 4 unpaired electrons
    # sextet  - 5 unpaired electrons

    energies = {}
    atoms = cheminfo.MULTIPLICITY.keys()

    for atom in atoms:

        label = "_tmp_atom_" + atom
        multiplicity = cheminfo.MULTIPLICITY[atom]
        keyword = None

        if multiplicity == 1:
            keyword = "singlet"
        elif multiplicity == 2:
            keyword = "doublet"
        elif multiplicity == 3:
            keyword = "triplet"
        elif multiplicity == 4:
            keyword = "quartet"
        elif multiplicity == 5:
            keyword = "quintet"
        elif multiplicity == 6:
            keyword = "sextet"

        calculator = Mopac(method=method,
                           task="uhf precise charge=0 {}".format(keyword),
                           label=label)
        atomobj = ase.Atoms(atom, calculator=calculator)
        calculator.write_input(atomobj)

        cmd = calculator.command
        cmd = cmd.replace("PREFIX", label)
        run_mopac(cmd)

        # Line
        line = read_line(label + ".out", "FINAL HEAT OF FORMATION")
        print(line, atom)
        line = line.split()

        hof = line[5]
        energies[atom] = float(hof)

    return energies
예제 #6
0
def test_mopac():
    """Test H2 molecule atomization with MOPAC."""
    from ase.build import molecule
    from ase.calculators.mopac import MOPAC
    from ase.optimize import BFGS
    h2 = molecule('H2', calculator=MOPAC(label='h2'))
    BFGS(h2, trajectory='h2.traj').run(fmax=0.01)
    e2 = h2.get_potential_energy()
    h1 = h2.copy()
    del h1[1]
    h1.set_initial_magnetic_moments([1])
    h1.calc = MOPAC(label='h1')
    e1 = h1.get_potential_energy()
    d = h2.get_distance(0, 1)
    ea = 2 * e1 - e2
    print(d, ea)
    assert abs(d - 0.759) < 0.001
    assert abs(ea - 5.907) < 0.001
    h2o = molecule('H2O', calculator=MOPAC(label='h2o', tasks='GRADIENTS'))
    h2o.get_potential_energy()
    print('dipole:', h2o.get_dipole_moment())
    atoms = MOPAC.read_atoms('h2')
    print('magmom:', atoms.calc.get_magnetic_moment())
    print('PM7 h**o lumo:', atoms.calc.get_homo_lumo_levels())
    atoms.calc.set(method='AM1')
    atoms.get_potential_energy()
    print('AM1 h**o lumo:', atoms.calc.get_homo_lumo_levels())
    calc = MOPAC(restart='h1')
    print('magmom:', calc.get_magnetic_moment())
예제 #7
0
파일: mopac.py 프로젝트: puckvg/chemhelp
def calculate(atoms,
              coord,
              parameters=DEFAULT_PARAMETERS,
              label=None,
              write_only=True,
              n_threads=1,
              clean=False):

    # SET n_threads

    if label is None:
        label = "_tmp_mopac_"

    method = parameters["method"]
    keywords = parameters["keywords"]

    calculator = Mopac(method=method, task=keywords, label=label)

    molecule = ase.Atoms(atoms, coord)
    molecule.set_calculator(calculator)

    calculator.write_input(molecule)

    if write_only:
        return None

    # TODO TODO TODO
    run_mopac(label + ".mop")

    # read log
    properties = read_properties(label + ".out")

    if clean:
        pass
        # TODO Remove label.mop label.out label.arc label.ase

    return properties
예제 #8
0
    def geo_opt(self, inputXYZ):
        # name
        name = inputXYZ[:-4]
        self.trj = '%s.trj' % name
        self.rst = '%s.rst' % name
        self.log = '%s.log' % name
        opted_xyz = '%s_opted.xyz' % name  # requires to have trj

        # read the coordinates
        atoms = read(inputXYZ)

        # configuration
        os.environ[
            'ASE_MOPAC_COMMAND'] = '%s PREFIX.mop 2> /dev/null' % self.mopac
        os.environ['LD_LIBRARY_PATH'] = '%s:$LD_LIBRARY_PATH' % self.mopaclib
        calc = MOPAC(label=name,
                     uhf=self.uks,
                     method=self.method,
                     task='%s THREADS=%s CHARGE=%s EPS=%s' %
                     (self.task, self.processors, self.charge, self.eps))
        #calc = MOPAC()
        #print(os.environ)
        #print(calc.parameters)

        atoms.set_calculator(calc)

        # optimization
        dyn = BFGS(atoms,
                   trajectory=self.trj,
                   restart=self.rst,
                   logfile=self.log)
        dyn.run(fmax=self.fmax, steps=self.steps)

        # convert the last frame to xyz
        frm = read(self.trj, -1)
        frm.write(opted_xyz, 'xyz')
예제 #9
0
파일: mopac.py 프로젝트: uu1477/MyAse
"""Test H2 molecule atomization with MOPAC."""
from ase.build import molecule
from ase.calculators.mopac import MOPAC
from ase.optimize import BFGS
h2 = molecule('H2', calculator=MOPAC(label='h2'))
BFGS(h2, trajectory='h2.traj').run(fmax=0.01)
e2 = h2.get_potential_energy()
h1 = h2.copy()
del h1[1]
h1.set_initial_magnetic_moments([1])
h1.calc = MOPAC(label='h1')
e1 = h1.get_potential_energy()
d = h2.get_distance(0, 1)
ea = 2 * e1 - e2
print(d, ea)
assert abs(d - 0.759) < 0.001
assert abs(ea - 5.907) < 0.001
예제 #10
0
def get_ase_calc(embedder):
    '''
    Attach the correct ASE calculator
    to the ASE Atoms object.
    embedder: either a TSCoDe embedder object or
        a 4-element strings tuple containing
        (calculator, method, procs, solvent)
    '''
    if isinstance(embedder, tuple):
        calculator, method, procs, solvent = embedder

    else:
        calculator = embedder.options.calculator
        method = embedder.options.theory_level
        procs = embedder.options.procs
        solvent = embedder.options.solvent

    if calculator == 'XTB':
        try:
            from xtb.ase.calculator import XTB
        except ImportError:
            raise Exception(
                ('Cannot import xtb python bindings. Install them with:\n'
                 '>>> conda install -c conda-forge xtb-python\n'
                 '(See https://github.com/grimme-lab/xtb-python)'))

        from tscode.solvents import (solvent_synonyms, xtb_solvents,
                                     xtb_supported)

        solvent = solvent_synonyms[
            solvent] if solvent in solvent_synonyms else solvent
        solvent = 'none' if solvent is None else solvent

        if solvent not in xtb_solvents:
            raise Exception(
                f'Solvent \'{solvent}\' not supported by XTB. Supported solvents are:\n{xtb_supported}'
            )

        return XTB(method=method, solvent=solvent)

    command = COMMANDS[calculator]

    if calculator == 'MOPAC':

        if solvent is not None:
            method = method + ' ' + get_solvent_line(solvent, calculator,
                                                     method)

        return MOPAC(label='temp',
                     command=f'{command} temp.mop > temp.cmdlog 2>&1',
                     method=method + ' GEO-OK')

    if calculator == 'ORCA':

        orcablocks = ''

        if procs > 1:
            orcablocks += f'%pal nprocs {procs} end'

        if solvent is not None:
            orcablocks += get_solvent_line(solvent, calculator, method)

        return ORCA(label='temp',
                    command=f'{command} temp.inp > temp.out 2>&1',
                    orcasimpleinput=method,
                    orcablocks=orcablocks)

    if calculator == 'GAUSSIAN':

        if solvent is not None:
            method = method + ' ' + get_solvent_line(solvent, calculator,
                                                     method)

        mem = str(MEM_GB) + 'GB' if MEM_GB >= 1 else str(int(1000 *
                                                             MEM_GB)) + 'MB'

        calc = Gaussian(
            label='temp',
            command=f'{command} temp.com',
            method=method,
            nprocshared=procs,
            mem=mem,
        )

        if 'g09' in command:

            from ase.io import read

            def g09_read_results(self=calc):
                output = read(self.label + '.out', format='gaussian-out')
                self.calc = output.calc
                self.results = output.calc.results

            calc.read_results = g09_read_results

            # Adapting for g09 outputting .out files instead of g16 .log files.
            # This is a bad fix and the issue should be corrected in the ASE
            # source code: merge request on GitHub pending to be written

            return calc
예제 #11
0
""" wrapper script to evaluate semiempirical hamiltonians on xyz files """
import sys
from ase.calculators.mopac import MOPAC
from ase.io import read
import subprocess
import os

try:
    methods, coordinates = sys.argv[1:]
except:
    print('Usage: %s METHODS coord.xyz' % sys.argv[0])
    exit(2)

mol = read(coordinates)
for method in methods.split(','):
    mol.calc = MOPAC(label='workfile', method=method, task='', relscf=None)
    mol.calc.write_input(mol)
    if method in 'OM1 OM2 OM3'.split():
        runner = './run_mndo.sh'
        col = 4
    else:
        runner = './run_mopac.sh'
        col = 5
    with open(os.devnull, 'w') as devnull:
        subprocess.call(runner, stdout=devnull, stderr=devnull)
    lines = open('workfile.out').readlines()
    valid = [
        _.strip().split()[col] for _ in lines if 'FINAL HEAT OF FORMATION' in _
    ]
    if len(valid) != 1:
        continue
예제 #12
0
"""Test H2 molecule atomization with MOPAC."""
from ase.build import molecule
from ase.calculators.mopac import MOPAC
from ase.optimize import BFGS
h2 = molecule('H2', calculator=MOPAC(label='h2'))
BFGS(h2, trajectory='h2.traj').run(fmax=0.01)
e2 = h2.get_potential_energy()
h1 = h2.copy()
del h1[1]
h1.set_initial_magnetic_moments([1])
h1.calc = MOPAC(label='h1')
e1 = h1.get_potential_energy()
d = h2.get_distance(0, 1)
ea = 2 * e1 - e2
print(d, ea)
assert abs(d - 0.759) < 0.001
assert abs(ea - 5.907) < 0.001
h2o = molecule('H2O', calculator=MOPAC(label='h2o', tasks='GRADIENTS'))
h2o.get_potential_energy()
print('dipole:', h2o.get_dipole_moment())
atoms = MOPAC.read_atoms('h2')
print('magmom:', atoms.calc.get_magnetic_moment())
print('PM7 h**o lumo:', atoms.calc.get_homo_lumo_levels())
atoms.calc.set(method='AM1')
atoms.get_potential_energy()
print('AM1 h**o lumo:', atoms.calc.get_homo_lumo_levels())
calc = MOPAC(restart='h1')
print('magmom:', calc.get_magnetic_moment())