def optimize(self, calculator='siesta'):
        from ase.optimize import QuasiNewton

        if calculator == 'siesta':
            calc = Siesta(
                label=self.label,
                xc='CA',
                mesh_cutoff=400 * eV,
                energy_shift=0.03 * eV,
                basis_set='SZ',
                fdf_arguments=self.extra_fdf,
            )
        elif calculator == 'dftb':
            extras = {}
            for S in set(self.mol.get_chemical_symbols()):
                key = 'Hamiltonian_MaxAngularMomentum_' + S
                if S == 'H':
                    value = '"s"'
                else:
                    value = '"p"'
                extras[key] = value
            calc = Dftb(label=self.label, atoms=self.mol, **extras)

        tempdir = "." + self.label
        try:
            os.mkdir(tempdir)
        except:
            pass

        os.chdir(tempdir)
        self.mol.set_calculator(calc)
        dyn = QuasiNewton(self.mol, trajectory=self.label + '.traj')
        dyn.run(fmax=0.5)
        os.chdir('../')
Exemplo n.º 2
0
    def get_ground_state(self, atoms, **kw):
        """
        Run siesta calculations in order to get ground state properties.
        Makes sure that the proper parameters are unsed in order to be able
        to run pynao afterward, i.e.,

            COOP.Write = True
            WriteDenchar = True
            XML.Write = True
        """
        from ase.calculators.siesta import Siesta

        if "fdf_arguments" not in kw.keys():
            kw["fdf_arguments"] = {
                "COOP.Write": True,
                "WriteDenchar": True,
                "XML.Write": True
            }
        else:
            for param in ["COOP.Write", "WriteDenchar", "XML.Write"]:
                kw["fdf_arguments"][param] = True

        siesta = Siesta(**kw)
        atoms.calc = siesta
        atoms.get_potential_energy()
Exemplo n.º 3
0
 def add_calculator(self):
     self.set_calculator(Siesta(label=self.label,
                   xc='CA',
                   mesh_cutoff=400 * eV,
                   energy_shift=0.03 * eV,
                   basis_set='SZ',
                   fdf_arguments=self.extra_fdf,
                   ))
Exemplo n.º 4
0
def test_bands():
    from ase.build import bulk
    from ase.calculators.siesta import Siesta
    from ase.utils import workdir
    from ase.dft.band_structure import calculate_band_structure

    atoms = bulk('Si')
    with workdir('files', mkdir=True):
        path = atoms.cell.bandpath('GXWK', density=10)
        atoms.calc = Siesta(kpts=[2, 2, 2])
        bs = calculate_band_structure(atoms, path)
        print(bs)
        bs.write('bs.json')
Exemplo n.º 5
0
def calculate_siesta(i):
    siesta = Siesta(label = 'image-{}'.format(i),
    xc = 'PBE',
    mesh_cutoff = 400 * Ry,
    energy_shift = 0.03,
    basis_set = 'DZP',
    spin = 'UNPOLARIZED',
    kpts = [9,5,1],
    fdf_arguments={'Diag.ParallelOverK': True,
                   'MaxSCFIterations':   300,
                   'DM.MixingWeight':    0.10,
                   'DM.NumberPulay':     5,
                   'DM.NumberKick':      50})
    return siesta
Exemplo n.º 6
0
def test_fdf_io():
    from ase.build import bulk
    from ase.calculators.siesta import Siesta
    from ase.io.siesta import _read_fdf_lines

    atoms = bulk('Ti')
    calc = Siesta()
    atoms.calc = calc
    calc.write_input(atoms, properties=['energy'])
    # Should produce siesta.fdf but really we should be more explicit

    fname = 'siesta.fdf'

    with open(fname) as fd:
        thing = _read_fdf_lines(fd)
    print(thing)

    assert thing[0].split() == ['SystemName', 'siesta']
Exemplo n.º 7
0
def set_calculator_for_sp(atoms):
    """single point calculation using dftb calculator

    Parameters
    ----------
    atoms: the ase Atoms object to be set
    """
    import os

    os.environ["SIESTA_COMMAND"] = "/share/apps/siesta/bin/siesta-bzr-serial < ./%s > ./%s"
    os.environ["SIESTA_PP_PATH"] = "/share/apps/siesta/pp"

    from ase.calculators.siesta import Siesta

    atoms.set_calculator(Siesta(
        xc="GGA",
        basis_set='DZP',
        kpts=[1, 1, 1],
    ))
    def iter_md(self):
        calc = Siesta(
            label=self.label,
            xc='CA',
            mesh_cutoff=400 * eV,
            energy_shift=0.03 * eV,
            basis_set='SZ',
            fdf_arguments=self.extra_fdf,
        )

        tempdir = "." + self.label
        try:
            os.mkdir(tempdir)
        except:
            pass

        os.chdir(tempdir)
        self.mol.set_calculator(calc)
        E = self.mol.get_total_energy()
        os.chdir('../')
Exemplo n.º 9
0
# In this script the Virtual Crystal approximation is used to model
# a stronger affinity for positive charge on the H atoms.
# This could model interaction with other molecules not explicitly
# handled.
import numpy as np
from ase.calculators.siesta import Siesta
from ase.calculators.siesta.parameters import Species
from ase.optimize import QuasiNewton
from ase import Atoms

atoms = Atoms('CH4', np.array([
    [0.000000, 0.000000, 0.000000],
    [0.682793, 0.682793, 0.682793],
    [-0.682793, -0.682793, 0.682790],
    [-0.682793, 0.682793, -0.682793],
    [0.682793, -0.682793, -0.682793]]))

siesta = Siesta(
    species=[
        Species(symbol='H', excess_charge=0.1)])

atoms.calc = siesta
dyn = QuasiNewton(atoms, trajectory='h.traj')
dyn.run(fmax=0.02)
Exemplo n.º 10
0
from ase.io import read
from ase.constraints import FixAtoms
from ase.calculators.siesta import Siesta
from ase.md import VelocityVerlet
from ase import units

# Read in the geometry from a xyz file, set the cell, boundary conditions and center
atoms = read('geom.xyz')
atoms.set_cell([7.66348, 7.66348, 7.66348 * 2])
atoms.set_pbc((1, 1, 1))
atoms.center()

# Set initial velocities for hydrogen atoms along the z-direction
p = atoms.get_momenta()
p[0, 2] = -1.5
p[1, 2] = -1.5
atoms.set_momenta(p)

# Keep some atoms fixed during the simulation
atoms.set_constraint(FixAtoms(indices=range(18, 38)))

# Set the calculator and attach it to the system
calc = Siesta('si001+h2', basis='SZ', xc='PBE', meshcutoff=50 * units.Ry)
calc.set_fdf('PAO.EnergyShift', 0.25 * units.eV)
calc.set_fdf('PAO.SplitNorm', 0.15)
atoms.set_calculator(calc)

# Set the VelocityVerlet algorithm and run it
dyn = VelocityVerlet(atoms, dt=1.0 * units.fs, trajectory='si001+h2.traj')
dyn.run(steps=100)
Exemplo n.º 11
0
from ase import Atoms
from ase.calculators.siesta import Siesta
from ase.units import Ry

a0 = 5.43
bulk = Atoms('Si2', [(0, 0, 0), (0.25, 0.25, 0.25)], pbc=True)
b = a0 / 2
bulk.set_cell([(0, b, b), (b, 0, b), (b, b, 0)], scale_atoms=True)

calc = Siesta(
    label='Si',
    xc='PBE',
    mesh_cutoff=200 * Ry,
    energy_shift=0.01 * Ry,
    basis_set='DZ',
    kpts=[10, 10, 10],
    fdf_arguments={
        'DM.MixingWeight': 0.10,
        'MaxSCFIterations': 100
    },
)
bulk.set_calculator(calc)
e = bulk.get_potential_energy()
Exemplo n.º 12
0
from ase.calculators.siesta import Siesta
from ase.calculators.siesta.parameters import Species, PAOBasisBlock
from ase.optimize import QuasiNewton
from ase import Atoms

atoms = Atoms('3H', [(0.0, 0.0, 0.0), (0.0, 0.0, 0.5), (0.0, 0.0, 1.0)],
              cell=[10, 10, 10])

basis_set = PAOBasisBlock("""1
0  2 S 0.2
0.0 0.0""")
atoms.set_tags([0, 1, 0])
siesta = Siesta(species=[
    Species(symbol='H', tag=None, basis_set='SZ'),
    Species(symbol='H', tag=1, basis_set=basis_set, ghost=True)
])

atoms.set_calculator(siesta)
dyn = QuasiNewton(atoms, trajectory='h.traj')
dyn.run(fmax=0.02)
Exemplo n.º 13
0
from ase.build import bulk
from ase.calculators.siesta import Siesta
from ase.io.siesta import _read_fdf_lines

atoms = bulk('Ti')
calc = Siesta()
atoms.calc = calc
calc.write_input(atoms, properties=['energy'])
# Should produce siesta.fdf but really we should be more explicit

fname = 'siesta.fdf'

with open(fname) as fd:
    thing = _read_fdf_lines(fd)
print(thing)

assert thing[0].split() == ['SystemName', 'siesta']
Exemplo n.º 14
0
                       (-0.776070, 0.590459, 0.00000),
                       (0.000000, -0.007702, -0.000001)],
            pbc=(1, 1, 1))

# Center the molecule in the cell with some vacuum around
h2o.center(vacuum=6.0)

# Select some energy-shifts for the basis orbitals
e_shifts = [0.01, 0.1, 0.2, 0.3, 0.4, 0.5]

# Run the relaxation for each energy shift, and print out the
# corresponding total energy, bond length and angle

for e_s in e_shifts:
    starttime = time.time()
    calc = Siesta('h2o', meshcutoff=200.0 * units.Ry, mix=0.5, pulay=4)
    calc.set_fdf('PAO.EnergyShift', e_s * units.eV)
    calc.set_fdf('PAO.SplitNorm', 0.15)
    calc.set_fdf('PAO.BasisSize', 'SZ')
    h2o.set_calculator(calc)
    # Make a -traj file named h2o_current_shift.traj:
    dyn = QuasiNewton(h2o, trajectory='h2o_%s.traj' % e_s)
    dyn.run(fmax=0.02)  # Perform the relaxation
    E = h2o.get_potential_energy()
    print  # Make the output more readable
    print "E_shift: %.2f" % e_s
    print "----------------"
    print "Total Energy: %.4f" % E  # Print total energy
    d = h2o.get_distance(0, 2)
    print "Bond length: %.4f" % d  # Print bond length
    p = h2o.positions
Exemplo n.º 15
0
# https://github.com/maxhutch/quantum-espresso/blob/master/PHonon/examples/example15/README

CO2 = Atoms('CO2',
            positions=[[-0.009026, -0.020241, 0.026760],
                       [1.167544, 0.012723, 0.071808],
                       [-1.185592, -0.053316, -0.017945]],
            cell=[20, 20, 20])

# enter siesta input
siesta = Siesta(mesh_cutoff=150 * Ry,
                basis_set='DZP',
                pseudo_qualifier='',
                energy_shift=(10 * 10**-3) * eV,
                fdf_arguments={
                    'SCFMustConverge': False,
                    'COOP.Write': True,
                    'WriteDenchar': True,
                    'PAO.BasisType': 'split',
                    'DM.Tolerance': 1e-4,
                    'DM.MixingWeight': 0.01,
                    'MaxSCFIterations': 300,
                    'DM.NumberPulay': 4
                })

CO2.set_calculator(siesta)

ram = SiestaRaman(CO2,
                  siesta,
                  label="siesta",
                  jcutoff=7,
                  iter_broadening=0.15 / Ha,
                  xc_code='LDA,PZ',
Exemplo n.º 16
0
 def calc(self, **kwargs):
     from ase.calculators.siesta import Siesta
     command = '{} < PREFIX.fdf > PREFIX.out'.format(self.executable)
     return Siesta(command=command,
                   pseudo_path=str(self.pseudo_path),
                   **kwargs)
Exemplo n.º 17
0
from ase import Atoms
from ase.calculators.siesta import Siesta
from ase.units import Ry

a0 = 5.43
bulk = Atoms('Si2', [(0, 0, 0), (0.25, 0.25, 0.25)], pbc=True)
b = a0 / 2
bulk.set_cell([(0, b, b), (b, 0, b), (b, b, 0)], scale_atoms=True)

calc = Siesta(
    label='Si',
    xc='PBE',
    spin='collinear',
    mesh_cutoff=200 * Ry,
    energy_shift=0.01 * Ry,
    basis_set='DZ',
    kpts=[1, 2, 3],
    fdf_arguments={
        'DM.MixingWeight': 0.10,
        'MaxSCFIterations': 10,
        'SCF.DM.Tolerance': 0.1,
    },
)
bulk.calc = calc
e = bulk.get_potential_energy()
print(e)
Exemplo n.º 18
0
from ase.build import bulk
from ase.calculators.siesta import Siesta
from ase.utils import workdir
from ase.dft.band_structure import calculate_band_structure

atoms = bulk('Si')
with workdir('files', mkdir=True):
    path = atoms.cell.bandpath('GXWK', density=10)
    atoms.calc = Siesta(kpts=[2, 2, 2])
    bs = calculate_band_structure(atoms, path)
    print(bs)
    bs.write('bs.json')
Exemplo n.º 19
0
from ase.calculators.siesta import Siesta
from ase.optimize import BFGS
from ase.calculators.socketio import SocketIOCalculator

unixsocket = 'siesta'

fdf_arguments = {'MD.TypeOfRun': 'Master',
                 'Master.code': 'i-pi',
                 'Master.interface': 'socket',
                 'Master.address': unixsocket,
                 'Master.socketType': 'unix'}

# To connect through INET socket instead, use:
#   fdf_arguments['Master.port'] = port
#   fdf_arguments['Master.socketType'] = 'inet'
# Optional, for networking:
#   fdf_arguments['Master.address'] = <hostname or IP address>

atoms = molecule('H2O', vacuum=3.0)
atoms.rattle(stdev=0.1)

siesta = Siesta(fdf_arguments=fdf_arguments)
opt = BFGS(atoms, trajectory='opt.siesta.traj', logfile='opt.siesta.log')

with SocketIOCalculator(siesta, log=sys.stdout,
                        unixsocket=unixsocket) as calc:
    atoms.calc = calc
    opt.run(fmax=0.05)

# Note: Siesta does not exit cleanly - expect nonzero exit codes.
Exemplo n.º 20
0
from ase.calculators.siesta import Siesta
from ase.units import Ry, eV, Ang
from ase.visualize import view
from ase.optimize import QuasiNewton, BFGS
from ase.io import write, read

atoms = read('initial-input.xyz')

siesta = Siesta(label='initial',
                xc='PBE',
                mesh_cutoff=400 * Ry,
                energy_shift=0.03,
                basis_set='DZP',
                spin='UNPOLARIZED',
                kpts=[9, 5, 1],
                fdf_arguments={
                    'Diag.ParallelOverK': True,
                    'MaxSCFIterations': 300,
                    'DM.MixingWeight': 0.10,
                    'DM.NumberPulay': 5,
                    'DM.NumberKick': 50,
                    'WriteMDXmol': True
                })

atoms.set_calculator(siesta)
#eng = atoms.get_potential_energy()

dynamics = BFGS(atoms=atoms, trajectory='initial-relax.traj')
dynamics.run(fmax=0.01)

# convert to xyz file
Exemplo n.º 21
0
 def prepare_input(self, struct):
     if self.calculator == "VASP":
         # POTCAR and POSCAR file generation, INCAR and KPOINTS must be provided in current dir
         write(filename="POSCAR", images=struct, format="vasp")
         if os.path.isfile('POTCAR'):
             os.system("rm POTCAR")
         tmp = open("POSCAR", "r")
         first_line = tmp.readline()
         line_sp = first_line.split()
         cat = "cat "
         # path from NGOptConfig
         for s in line_sp:
             cat = cat + self.vasp_pseudo_path + "/POTCAR_" + s + " "
         cat = cat + " > POTCAR"
         tmp.close()
         os.system(cat)
     if self.calculator == "siesta":
         # head.fdf file generation, tail.fdf must be provided in current dir
         calc = Siesta(
             label='siesta',
             xc='PBE',
             basis_set='SZP',
         )
         f = open("head.fdf", "w")
         calc._write_species(f, struct)
         calc._write_structure(f, struct)
         f.close()
         os.system("cat head.fdf tail.fdf > siesta.fdf")
     if self.calculator == "openmx":
         # center of file generation, head and tail must be provided in current dir
         label = "openmx"
         input = open("openmx.in.dat", "w")
         #
         input.write("\n")
         input.write("System.Name                      " + label + "\n")
         input.write("\n")
         input.write("# \n")
         input.write("# Definition of Atomic Species \n")
         input.write("# \n")
         input.write("\n")
         # print openmx species
         l = len(struct.get_chemical_symbols())
         symbols = struct.get_chemical_symbols()
         symbols_dist = set(symbols)
         input.write("Species.Number       " + str(len(symbols_dist)) +
                     "\n")
         input.write("<Definition.of.Atomic.Species \n")
         for symbol in symbols_dist:
             basis = get_basis_info_openmx(self.openmx_bases_file, symbol)
             pseudo = get_pseudos_openmx(self.openmx_pseudo_file, symbol)
             size = str(basis[2])
             input.write(
                 str(symbol) + "  " + str(basis[0] + "-" + size) + "  " +
                 str(pseudo) + " \n")
         input.write("Definition.of.Atomic.Species> \n")
         input.write("\n")
         input.write("# \n")
         input.write("# Atoms \n")
         input.write("# \n")
         input.write("\n")
         # print openmx positions
         positions = struct.get_positions()
         input.write("Atoms.Number      " + str(l) + "\n")
         input.write("Atoms.SpeciesAndCoordinates.Unit   Ang # Ang|AU \n")
         input.write("<Atoms.SpeciesAndCoordinates \n")
         for i in range(l):
             symbol = symbols[i]
             basis = get_basis_info_openmx(self.openmx_bases_file, symbol)
             valence = float(basis[1]) / 2.
             if basis[2] == "s2p2d2":
                 valence1 = valence + self.halfmom
                 valence2 = valence - self.halfmom
             else:
                 valence1 = valence2 = valence
                 # valence1 = valence+self.halfmom
                 # valence2 = valence-self.halfmom
             input.write(
                 str(i + 1) + "    " + str(symbols[i]) + "    " +
                 str(format(positions[i][0], '.12f')) + "   " +
                 str(format(positions[i][1], '.12f')) + "   " +
                 str(format(positions[i][2], '.12f')) + "    " +
                 str(valence1) + "    " + str(valence2) + "\n")
         input.write("Atoms.SpeciesAndCoordinates> \n")
         # print openmx unit cell
         input.write("Atoms.UnitVectors.Unit             Ang # Ang|AU \n"
                     )  # do poprawy!
         input.write("<Atoms.UnitVectors \n")
         cell = struct.get_cell()
         input.write(
             str(format(cell[0][0], '.12f')) + "    " +
             str(format(cell[0][1], '.12f')) + "    " +
             str(format(cell[0][2], '.12f')) + "\n")
         input.write(
             str(format(cell[1][0], '.12f')) + "    " +
             str(format(cell[1][1], '.12f')) + "    " +
             str(format(cell[1][2], '.12f')) + "\n")
         input.write(
             str(format(cell[2][0], '.12f')) + "    " +
             str(format(cell[2][1], '.12f')) + "    " +
             str(format(cell[2][2], '.12f')) + "\n")
         input.write("Atoms.UnitVectors> \n")
         input.close()
         os.system("cat head openmx.in.dat tail > openmx.dat")