示例#1
0
def test2(pw=300, kpts=(6, 6, 6), vaspcmd='mr vasp'):
    """Performs a test stress-strain calculation with vasp module for fcc Pt."""

    v = VASP(pw=pw, kpts=kpts, name='fccPt', vaspcmd=vaspcmd)

    from ASE import ListOfAtoms, Atom

    atoms = ListOfAtoms([
        Atom('Pt', [0, 0, 0]),
        Atom('Pt', [0.5, 0.5, 0]),
        Atom('Pt', [0.5, 0, 0.5]),
        Atom('Pt', [0, 0.5, 0.5])
    ])

    uc = [[4.05, 0, 0], [0.0, 4.05, 0], [0.0, 0, 4.05]]

    atoms.SetUnitCell(uc)

    atoms.SetCalculator(v)

    import ASE.Utilities.GeometricTransforms as ASEgeotrans

    initvol = atoms.GetUnitCellVolume()

    vols, energies = [], []

    #for f in [0.8, 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15]:
    for f in [0.9, 0.95, 1.0, 1.05, 1.1]:
        ASEgeotrans.SetUnitCellVolume(atoms, f * initvol)

        #v.SetName('%1.2f_eos' % f)
        #print v.GetStress()
        vols.append(atoms.GetUnitCellVolume())
        energies.append(atoms.GetPotentialEnergy())

    import pylab as pl

    pl.plot(vols, energies, 'ko ')
    pl.show()

    import ASE.Utilities.EquationOfState as ASEeos

    eos = ASEeos.EquationOfState('Murnaghan', vols, energies)
    # print the minimum volume, energy, bulk modulus and pressure
    print eos
    g = eos.GetPlot()
    eos.SavePlot('murn.png')  #save the figure as a png
    return
示例#2
0
 def Transmutate(self, new_species):
     """ Return a copy of this atom transmutated into a different species"""
     return Atom(species=new_species,
                 position=self.position,
                 tag=self.tag,
                 momentum=self.momentum,
                 magmom=self.magmom)
示例#3
0
 def Copy(self):
     """ Return an exact copy of this atom"""
     return Atom(species=self.species,
                 position=self.position,
                 tag=self.tag,
                 momentum=self.momentum,
                 magmom=self.magmom)
示例#4
0
 def Copy(self):
     return Atom(position=self.position,
                 Z=self.Z,
                 mass=self.mass,
                 tag=self.tag,
                 momentum=self.momentum,
                 magmom=self.magmom,
                 label=self.label,
                 valence_gs=self.valence_gs)
示例#5
0
def test1(pw=300, kpts=(6, 6, 6), vaspcmd='mr vasp'):
    """Performs a test single-point energy calculation with vasp module for B2 FeAl."""

    print "Test single-point energy calculation with vasp module for B2 FeAl."

    v = VASP(pw=pw, kpts=kpts, name='FeAl', vaspcmd=vaspcmd)

    from ASE import ListOfAtoms, Atom

    atoms = ListOfAtoms(
        [Atom('Fe', [0.0, 0.0, 0.0]),
         Atom('Al', [0.5, 0.5, 0.5])])

    uc = [[2.87, 0.00, 0.00], [0.00, 2.87, 0.00], [0.00, 0.00, 2.87]]

    atoms.SetUnitCell(uc)
    atoms.SetCalculator(v)

    print "Potential energy: ", v.GetPotentialEnergy()
    return
示例#6
0
 def __init__(self, calc, atoms=None):
     self.calc = calc
         
     if atoms is None:
         try:
             self.atoms = calc.GetListOfAtoms()
         except AttributeError:
             self.atoms = None
     else:
         from ASE import Atom, ListOfAtoms
         
         numbers = atoms.get_atomic_numbers()
         positions = atoms.get_positions()
         magmoms = atoms.get_initial_magnetic_moments()
         self.atoms = ListOfAtoms(
             [Atom(Z=numbers[a], position=positions[a], magmom=magmoms[a])
              for a in range(len(atoms))],
             cell=npy2num(atoms.get_cell()),
             periodic=tuple(atoms.get_pbc()))
         self.atoms.SetCalculator(calc)
示例#7
0
    def update(self, atoms):
        from Dacapo import Dacapo
        if self.calc is None:
            if 'nbands' not in self.kwargs:
                n = sum([valence[atom.symbol] for atom in atoms])
                self.kwargs['nbands'] = int(n * 0.65) + 4

            magmoms = atoms.get_initial_magnetic_moments()
            if magmoms.any():
                self.kwargs['spinpol'] = True

            self.calc = Dacapo(**self.kwargs)

            if self.stay_alive:
                self.calc.StayAliveOn()
            else:
                self.calc.StayAliveOff()

            if self.stress:
                self.calc.CalculateStress()

            for Z, path in self.pps:
                self.calc.SetPseudoPotential(Z, path)

        if self.loa is None:
            from ASE import Atom, ListOfAtoms
            numbers = atoms.get_atomic_numbers()
            positions = atoms.get_positions()
            magmoms = atoms.get_initial_magnetic_moments()
            self.loa = ListOfAtoms([
                Atom(Z=numbers[a], position=positions[a], magmom=magmoms[a])
                for a in range(len(atoms))
            ],
                                   cell=np2num(atoms.get_cell()),
                                   periodic=tuple(atoms.get_pbc()))
            self.loa.SetCalculator(self.calc)
        else:
            self.loa.SetCartesianPositions(np2num(atoms.get_positions()))
            self.loa.SetUnitCell(np2num(atoms.get_cell()), fix=True)
示例#8
0
    def initCoord(self, filepath):
        """Imports the coordinates (the rest is ignored) of a brenner *.d file:
    # are comments that do not belong to the file:
      
      # textual description:
      diamond lattice       
      # atoms:                                     
      63  
      # start time and stepsize:
      0.20000000000E+01   0.50000000000E+00          
      # cube dimension:            
      0.20000000000E+03   0.20000000000E+03   0.20000000000E+03  
      #number,  element number, x,y,z coordinates, 1=movable 2=unmovable atom
      1    6   0.12239212990E+01  -0.37850461006E+01  -0.76280212402E+00  2 #
      2    6  -0.11044621468E+01  -0.38742597103E+01  -0.95745104551E+00  2
      ...
      63   1   0.72413903475E+00   0.10444240570E+02  -0.26598501205E+01  2

    """
        f = open(filepath, 'r')
        self.title = self.ReadLine(f)
        self.numAtoms = self.ReadInt(f, 1)[0]
        self.starttime, self.step = self.ReadFloat(f, 2)
        self.cubedimension = self.ReadFloat(f, 3)
        self.movable = []
        atoms = []
        for i in range(self.numAtoms):
            atomID = self.ReadInt(f, 1)[0]
            symbol = symbols[(self.ReadInt(f, 1)[0])]
            coord = self.ReadFloat(f, 3)
            movable = self.ReadInt(f, 1)
            atoms.append(Atom(symbol, coord))
            self.movable.append(movable[0])
        self.atoms = ListOfAtoms(
            atoms,
            [[self.cubedimension[0], 0, 0], [0, self.cubedimension[1], 0],
             [0, 0, self.cubedimension[2]]])
示例#9
0
  a = Atom(H,position=(0.4,0.1,0.2))
  b = Atom(O,(0.,0.,0.5))
  c = Atom(ON)
  cryst = Structure([a,b,c])
  """

    H = Species("H", label="H_surf")
    O = Species("O", label="O_bulk")
    O_ghost = Species("O", label="O_ghost")
    O_ghost.SetGhostCharacter(True)
    ON = Hybrid(label="ON-0.50000", valence_gs=[[2, 2], [1.0, 3.5]], mass=4.6)

    basis_options = """
       PAO.BasisSize DZP
       PAO.EnergyShift 0.001 Ry
       PAO.SoftDefault T
     """
    ##  O.GenerateBasis(basis_options,"O.psf")

    a = Atom(H, position=(0.4, 0.1, 0.2))
    b = Atom(O, (0., 0., 0.5))
    c = Atom(ON)
    d = Atom(O_ghost, (-1.0, 0.3, 0.6))
    cryst = Structure([a, b, c, d])

    cryst.GetListOfSpecies()

    print cryst
    import sys
    cryst.write_in_fdf_form(sys.stdout)
示例#10
0
            f.write(" %10i %s %12.7f%12.7f%12.7f  0 0 0 0 0 0 0 0 0.000 \n" % \
                          (i+1, atom.symbol, xyz[0], xyz[1], xyz[2]))

    def plot_rasmol(self, repeat=(1, 1, 1)):
        from ASE.Visualization.RasMol import RasMol
        plot = RasMol(self, repeat)

    def plot_jmol(self, repeat=(1, 1, 1)):
        from ASE.IO.PDB import WritePDB
        import os
        new = self.Repeat(repeat)
        pdbfile = "tmp.pdb"
        WritePDB(pdbfile, atoms=new)
        os.system("jmol.sh " + pdbfile)


if __name__ == "__main__":

    a = Atom("H", label="H_surf", position=(0.4, 0.1, 0.2))
    b = Atom("O", (0., 0., 0.5), label="O_bulk")
    c = Atom(Z=0, label="ON-0.50000", valence_gs=[[0, 2], [1, 3.5]])
    cryst = Structure([a, b, c])

    print cryst
    import sys
    specs = cryst.GetSpeciesNumbers()
    print cryst.GetSpecies()
    cryst.write_in_fdf_form(sys.stdout)
    cryst.write_in_cif_form(sys.stdout)
    cryst.write_in_cssr_form(sys.stdout)
示例#11
0
from vasp.vasp import VASP
from vasp.parsing.SystemPM import *

from Atom import *
from UnitCell import *
from io import converters

uc = UnitCell()

vectors = [(4.05, 0.0, 0.0),
           (0.0, 4.05, 0.0),
           (0.0, 0.0, 4.05)]

uc.setCellVectors(vectors)

at1=Atom(symbol='Al') ; pos1=(0.0,0.0,0.0)
at2=Atom(symbol='Al') ; pos2=(0.0,0.5,0.5)
at3=Atom(symbol='Al') ; pos3=(0.5,0.0,0.5)
at4=Atom(symbol='Al') ; pos4=(0.5,0.5,0.0)

site1 = Site(pos1, at1)
site2 = Site(pos2, at2)
site3 = Site(pos3, at3)
site4 = Site(pos4, at4)

uc.addSite(site1, 'Al1')
uc.addSite(site2, 'Al2')
uc.addSite(site3, 'Al3')
uc.addSite(site4, 'Al4')

print uc
示例#12
0
文件: yl.py 项目: yihsuanliu/gpaw
import numpy as np

from ASE import Atom

from gpaw.utilities import equal
from gpaw.cluster import Cluster
from gpaw import Calculator
from gpaw.analyse.expandyl import ExpandYl

R = 1.
H2 = Cluster([Atom('H',(0,0,0)), Atom('H',(0,0,R))])
H2.minimal_box(3.)

calc = Calculator(h=0.2, width=0.01, nbands=2)
H2.SetCalculator(calc)
H2.GetPotentialEnergy()

yl = ExpandYl(H2.center_of_mass(), calc.wfs.gd, Rmax=2.5)
gl = []
for n in range(calc.nbands):
    psit_G = calc.kpt_u[0].psit_nG[n]
    norm = calc.wfs.gd.integrate(psit_G**2)
    g = yl.expand(psit_G)
    gsum = np.sum(g)

    # allow for 10 % inaccuracy in the norm
    print "norm, sum=", norm, gsum
    equal(norm, gsum, 0.1)
    
    gl.append(g/gsum*100)
示例#13
0
                    tag=self.tag,
                    momentum=self.momentum,
                    magmom=self.magmom,
                    label=self.label,
                    valence_gs=self.valence_gs)


#---------------------------------
class Crystal(ASE.ListOfAtoms):
    """ Extension of ListOfAtoms to provide new functionality """
    def SetPseudosInfo(self, func_pseudos):
        """ Installs a function to get the pseudopotentials"""
        self.get_pseudos = func_pseudos

    def GetPseudos(self):
        """ Gets the appropriate pseudopotentials"""
        return self.get_pseudos()


if __name__ == "__main__":
    a = Atom("H", label="H_surf")
    b = Atom("O", label="O_bulk")
    c = Atom(Z=0, label="ON-0.50000", valence_gs=[[0, 2], [1, 3.5]])
    cryst = Crystal([a, b, c])
    print cryst

    import siesta

    pepe = siesta.Siesta()
    pepe.run(cryst)
示例#14
0
    def ReadAtoms(name='.'):
        """Static method to read in the atoms."""

        f = open('POSCAR', 'r')
        lines = f.readlines()
        f.close()

        comment = lines[0]

        uc = []
        uc.append([float(x) for x in lines[2].split()])
        uc.append([float(x) for x in lines[3].split()])
        uc.append([float(x) for x in lines[4].split()])

        scalefactor = float(lines[1].strip())
        if scalefactor < 0:
            #that means this is the volume of the cell
            #vol = determinant of the uc
            vol0 = abs(num.determinant(uc))
            uc = abs(scalefactor) / vol0 * uc
        else:
            uc = scalefactor * num.array(uc)

        atomcounts = [int(x) for x in lines[5].split()]
        natoms = 0
        for count in atomcounts:
            natoms += count

        if lines[6][0] in ['s', 'S']:
            #selective dynamics were chosen, and positions start on line 7
            coordsys = lines[7][0]
            poscounter = 8
        else:
            coordsys = lines[6][0]
            poscounter = 7

        positions = []
        for i in range(natoms):
            pos = num.array([float(x) for x in lines[poscounter + i].split()])
            if coordsys[0] in ['C', 'c', 'K', 'k']:
                #cartesian coordinates, do nothing
                pass
            else:
                #direct coordinates. calculate cartesian coords
                pos = pos[0] * uc[0] + pos[1] * uc[1] + pos[2] * uc[2]

            positions.append(pos)

        positions = num.array(positions)

        #now get the identities from the POTCAR file.
        f = open('POTCAR', 'r')
        lines = f.readlines()
        f.close()
        #the start of each psp is either 'US symbol' 'PAW_GGA symbol
        #comment' or 'PAW_PBE symbol comment'
        tag, symbol = lines[0].split()
        regexp = re.compile('^\s+%s' % tag)

        psps = []
        for line in lines:
            if regexp.search(line):
                psps.append(line)

        #print atomcounts, psps
        if len(atomcounts) != len(psps):
            raise Exception, 'number of atom counts in POSCAR does not equal # of psps in POTCAR'

        from ASE import Atom, ListOfAtoms
        atoms = ListOfAtoms([])
        poscounter = 0
        for i, count in enumerate(atomcounts):
            tag, symbol = psps[i].split()
            for j in range(count):
                atoms.append(Atom(symbol, position=positions[poscounter]))
                poscounter += 1

        atoms.SetUnitCell(uc, fix=True)

        if os.path.exists('OUTCAR'):
            f = open('OUTCAR', 'r')

            regexp = re.compile('TOTAL-FORCE \(eV/Angst\)')
            lines = f.readlines()
            f.close()

            forcei = None
            for i, line in enumerate(lines):
                if regexp.search(line):
                    forcei = i + 2  #linenumber that forces start on
                    break
            if forcei is None:
                raise Exception, 'forcei is none, no forces found!'

            forces = []
            for i in range(len(atoms)):
                posforce = [float(x) for x in lines[forcei + i].split()]
                forces.append(posforce[3:])
        else:
            forces = [None for atom in atoms]

        for atom, force in zip(atoms, forces):
            #print force
            atom._SetCartesianForce(force)

        ### more code must be added to read in the calculator.
        calc = VASP()
        calc.incar = parser2.INPUT2('INCAR')
        return atoms