示例#1
0
def write_gaussian(filename, atoms):
    """Writes a basic Gaussian input file"""
# Since Gaussian prints the geometry directly into the input file, we'll just
# the write_input method from the Gaussian calculator, and just use the
# default settings
    calc = Gaussian()
    calc.initialize(atoms)
    calc.write_input(filename, atoms)
示例#2
0
文件: gaussian.py 项目: yfyh2013/ase
def write_gaussian(filename, atoms):
    """Writes a basic Gaussian input file"""
    # Since Gaussian prints the geometry directly into the input file, we'll just
    # the write_input method from the Gaussian calculator, and just use the
    # default settings
    calc = Gaussian()
    calc.initialize(atoms)
    calc.write_input(filename, atoms)
示例#3
0
def get_atomization(method, basis):

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

    for atom in atoms:

        multiplicity = cheminfo.MULTIPLICITY[atom]

        label = "_tmp_atom_" + atom

        calculator = GaussianCalculator(method=method,
                                        basis=basis,
                                        multiplicity=multiplicity,
                                        label=label)

        del calculator.parameters['force']

        atomobj = ase.Atoms(atom, calculator=calculator)

        calculator.write_input(atomobj)
        command = calculator.command
        command = command.replace("PREFIX", label)
        run_gaussian(command)

        if "G4" in method:
            pattern = method + " Enthalpy"
            line = read_line(label + ".log", pattern)
            line = line.split()
            value = line[2]
        else:
            line = read_line(label + ".log", "SCF Done:")
            line = line.split()
            value = line[4]

        value = float(value)
        energies[atom] = value

        print(atom, value)

    return energies
def write_gaussian(ase_object, out_dir, **kwargs):
    """
    Write a Gaussian input file based on an ase object.
    Params :: 
    ase_object: ASE IO Object: ASE file containing molecule used as input for 
        Gaussian input file
    out_dir: str: path of directory to write the Gaussian input file
    **kwargs: dict: additional arguments to modify behaviour of gaussian input

    Returns ::
    None

    """
     # this is used to identify the header line and replace it
    HEADER_FLAG = 'HEADER_FLAG'
    # change directory to destination where input file to be saved
    original_dir = getcwd()
    os.chdir(out_dir)
    gaussian_settings = {'method': HEADER_FLAG,
                            'basis': '6-31g',
                            'Opt': 'Tight',
                            'Freq': 'DiagFull ',
                            'multiplicity': 1,
                            'charge': 0,
                            'mem': '50GB',
                            'nproc': 20  # ***20 for Farber and 36 for Caviness 
                            }
    gaussian_settings.update(kwargs)
    # input file created will be gaussian_input.com
    calc = Gaussian(**gaussian_settings, label='gaussian_input')
    ase_object.set_calculator(calc)  
    calc.write_input(ase_object)
    # change back directories
    os.chdir(original_dir)
    format_root(header_flag=HEADER_FLAG,
                    file_name=os.path.join(out_dir, 'gaussian_input.com'))
示例#5
0
def test_write_gaussian_calc():
    ''' Tests writing an input file for a Gaussian calculator. Reads this
    back in and checks that we get the parameters we expect.

    This allows testing of 'addsec', 'extra', 'ioplist',
    which we weren't able to test by reading and then writing files.'''

    # Generate an atoms object and calculator to test writing to a gaussian
    # input file:
    atoms = Atoms('H2', [[0, 0, 0], [0, 0, 0.74]])
    params = {
        'mem': '1GB',
        'charge': 0,
        'mult': 1,
        'xc': 'PBE',
        'save': None,
        'basis': 'EPR-III',
        'scf': 'qc',
        'ioplist': ['1/2', '2/3'],
        'freq': 'readiso',
        'addsec': '297 3 1',
        'extra': 'Opt = Tight'
    }
    atoms.calc = Gaussian(**params)

    # Here we generate the params we expect to read back from the
    # input file:
    params_expected = {}
    for k, v in params.items():
        if v is None:
            params_expected[k] = ''
        elif type(v) in [list, int]:
            params_expected[k] = v
        else:
            params_expected[k] = v.lower()

    # We haven't specified the output type so it will be set to 'p'
    params_expected['output_type'] = 'p'

    # No method is set in the calculator, so the xc is used as the method.
    # The XC PBE should be converted to pbepbe automatically
    params_expected.pop('xc')
    params_expected['method'] = 'pbepbe'

    # The 'extra' text is added into the route section,
    # and will be read as a key-value pair.
    params_expected.pop('extra')
    params_expected['opt'] = 'tight'

    # Freq= ReadIso is always removed because ReadIso section
    # is converted into being saved in route section and nuclei
    # properties section:
    params_expected['freq'] = None

    # Addsec gets added to the end of the file.
    # We expect the addsec we have set to be read in
    # as the readiso section where temperature, pressure and scale are set.
    params_expected.pop('addsec')
    params_expected['temperature'] = '297'
    params_expected['pressure'] = '3'
    params_expected['scale'] = '1'

    # The IOPlist will be read in as a string:
    ioplist = params_expected.pop('ioplist')
    ioplist_txt = ''
    for iop in ioplist:
        ioplist_txt += iop + ', '
    ioplist_txt = ioplist_txt.strip(', ')
    params_expected['iop'] = ioplist_txt

    # We will request the forces property, so forces should be added to the
    # route section:
    params_expected['forces'] = None

    _test_write_gaussian(atoms, params_expected, properties='forces')

    calc = Gaussian(basis='gen')
    # Can't set basis to gen without defining basis set:
    with pytest.raises(InputError):
        calc.write_input(atoms)

    # Test case where we have the basis set in a separate file:
    basisfilename = 'basis.txt'
    with open(basisfilename, 'w+') as f:
        f.write(_basis_set_text)
    calc = Gaussian(basisfile=basisfilename,
                    output_type='p',
                    mult=0,
                    charge=1,
                    basis='gen')
    atoms.calc = calc
    params_expected = calc.parameters
    params_expected['basis_set'] = _basis_set_text
    _test_write_gaussian(atoms, params_expected, properties='forces')
示例#6
0
def calculate(atoms,
              coordinates,
              parameters=DEFAULT_PARAMETERS,
              label=None,
              write_only=True,
              n_threads=1,
              mem=1):
    """

    """

    if label is None:
        filename = "_tmp_" + "gaussian"
    else:
        filename = label

    comfile = filename + ".com"

    method = parameters["method"]
    basis = parameters["basis"]

    if parameters["opt"] is not None:
        calculator = GaussianCalculator(method=method,
                                        basis=basis,
                                        opt=parameters["opt"],
                                        Freq="()",
                                        label=filename)
    else:
        calculator = GaussianCalculator(method=method,
                                        basis=basis,
                                        label=filename)

    if parameters['force'] is None:
        del calculator.parameters['force']

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

    calculator.write_input(molecule)

    if n_threads > 1:
        jstr = r"%nprocshared={:}\n%mem={:}GB".format(n_threads, mem)
        cmd = ["sed", "-i", "' 1 s/.*/" + jstr + r"\n&/'", comfile]
        cmd = " ".join(cmd)
        subprocess.call(cmd, shell=True)

    if write_only:
        return True

    # Calculate
    command = calculator.command
    command = command.replace("PREFIX", filename)
    run_gaussian(command)

    # calculator = molecule.get_calculator()
    # calculator.calculate()

    # molecule.get_potential_energy()

    help(calculator)

    # TODO Get All Properties
    properties = read_properties(filename + ".log")

    return properties