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
def SortAtomListBySpecies(self): """Returns a dictionary with atoms sorted according to species The dictionary will have the atomtypes of the different atomic species found in the list of atoms as keys. The corresponding values will be a list of atoms containing the atoms of the given type. """ dictofspecies = {} for atom in self.GetListOfAtoms(): if dictofspecies.has_key(atom.GetChemicalSymbol()): dictofspecies[atom.GetChemicalSymbol()].append(atom.Copy()) else: atomlist = self.GetListOfAtoms().Copy() atomlist.data = ListOfAtoms([atom.Copy()]) unitcell = copy.copy(atomlist.GetUnitCell()) atomlist.data.SetUnitCell(unitcell, fix=True) dictofspecies[atom.GetChemicalSymbol()] = atomlist.data return dictofspecies
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)
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
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)
def afunc(var, data=None): rcs, rcp = var[0], var[1] f = open("base.fdf", "w") f.write("%block PAO.Basis\n Ga 2\n") f.write(" 0 1\n") f.write("%10.5f\n1.0\n" % (rcs, )) f.write("1 1\n") f.write("%10.5f\n1.0\n" % (rcp, )) f.write("%endblock PAO.Basis\n") f.close() atoms = ListOfAtoms([ Atom('Ga', (0.0, 0.0, 0.0), magmom=0), Atom('Ga', (2.0, 0.0, 0.0), magmom=0) ]) a = Siesta(executable="/Users/ag/bin/siesta-xlf") a.SetOption("%include", "base.fdf") energy = a.run(atoms) print rcs, rcp, energy return -energy
1.00000 1.00000 n=6 1 2 E 2.50435 0.86601 6.12615 5.62330 1.00000 1.00000 n=6 2 1 E 135.64896 4.82387 5.14075 1.00000 %EndBlock PAO.Basis """) URLbase = "http://fisica.ehu.es/ag/siesta-psffiles/" urllib.urlretrieve(URLbase + "Pb.psf", "Pb.psf") cell = Num.array([ [0.5,0.5,0.0], [0.5,0.0,0.5], [0.0,0.5,0.5]]) cell = 4.89*cell atoms = ListOfAtoms([Atom('Pb', (0.0,0.0,0.0))], cell=cell, periodic=1) for i in range(len(cutoffs)): cutoff = cutoffs[i] print i, cutoff a = Siesta(executable="$HOME/bin/siesta-2.6.9") # Initialize object ### a.SetOption("FilterCutoff"," 100.0 Ry") # Optional Filtering a.SetOption("Meshcutoff", str(cutoff)+" Ry") a.SetOption("%include"," basis.fdf") energy[i], dum, dum2 = a.run(atoms) # Run Siesta and get the (free)energy # # Plot # p.add(biggles.Curve(cutoffs[:],energy[:])) p.show()
# create a work subdirectory orig_dir = os.getcwd() dir = "bond_work" if os.path.isdir(dir): # does dir exist? shutil.rmtree(dir) # yes, remove old directory os.mkdir(dir) # make dir directory os.chdir(dir) # move to dir URLbase = "http://fisica.ehu.es/ag/siesta-psffiles/" urllib.urlretrieve(URLbase + "H.psf", "H.psf") urllib.urlretrieve(URLbase + "O.psf", "O.psf") for i in range(len(bonds)): d = bonds[i] print i, d atoms = ListOfAtoms([ Atom('H', (d * math.cos(theta), d * math.sin(theta), 0.0), magmom=1), Atom('H', (-d * math.cos(theta), d * math.sin(theta), 0.0), magmom=1), Atom('O', (0, 0, 0), magmom=1) ]) # cell=(4, 4, 4), periodic=1) energy[i] = a.run(atoms) # Run Siesta and get the (free)energy # # Plot # p.add(biggles.Curve(bonds[:], energy[:])) p.show() os.chdir(orig_dir)
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