示例#1
0
文件: md.py 项目: molguin-qc/hotbit
 def __call__(self):
     """ Writes trajectory file for current atoms list. """
     from ase import PickleTrajectory
     traj = PickleTrajectory('%s_it%i.trj' %(self.name,self.i), 'w')
     for image in self.images:
         traj.write(image)
     self.i+=1 
示例#2
0
文件: atoms.py 项目: nateharms/hotbit
class ExtendedTrajectory:
    def __init__(self,filename,atoms,n,mode='w',fixrcm=False):
        """
        Trajectory for multiple copies of unit cell.

        parameters:
        ===========
        filename:    output .traj -file
        atoms:       hotbit.Atoms object
        n:           tuple of number of symmetry operations
                     or list of tuples for the symmetry operations
        mode:        'w' write or 'a' append
        fixrcm:      Write trajectory with center of mass fixed at origin.
        """
        self.atoms = atoms
        self.n = n
        self.ext = self.atoms.extended_copy(n)
        self.traj = PickleTrajectory(filename,mode,self.ext) #,properties=['energy'])
        self.fixrcm = fixrcm

    def set_atoms(self,atoms):
        self.atoms = atoms
        self.ext = self.atoms.extended_copy(self.n)
        self.traj.set_atoms(self.ext)

    def write(self):
        cp = self.atoms.extended_copy(self.n)
        if self.fixrcm:
            cp.translate( -cp.get_center_of_mass() )
        self.ext.set_positions( cp.get_positions() )
        self.traj.write()
示例#3
0
文件: atoms.py 项目: pekkosk/hotbit
class ExtendedTrajectory:
    def __init__(self,filename,atoms,n,mode='w',fixrcm=False):
        """
        Trajectory for multiple copies of unit cell.

        parameters:
        ===========
        filename:    output .traj -file
        atoms:       hotbit.Atoms object
        n:           tuple of number of symmetry operations
                     or list of tuples for the symmetry operations
        mode:        'w' write or 'a' append
        fixrcm:      Write trajectory with center of mass fixed at origin.
        """
        self.atoms = atoms
        self.n = n
        self.ext = self.atoms.extended_copy(n)
        self.traj = PickleTrajectory(filename,mode,self.ext) #,properties=['energy'])
        self.fixrcm = fixrcm

    def set_atoms(self,atoms):
        self.atoms = atoms
        self.ext = self.atoms.extended_copy(self.n)
        self.traj.set_atoms(self.ext)

    def write(self):
        cp = self.atoms.extended_copy(self.n)
        if self.fixrcm:
            cp.translate( -cp.get_center_of_mass() )
        self.ext.set_positions( cp.get_positions() )
        self.traj.write()
示例#4
0
 def __call__(self):
     """ Writes trajectory file for current atoms list. """
     from ase import PickleTrajectory
     traj = PickleTrajectory('%s_it%i.trj' % (self.name, self.i), 'w')
     for image in self.images:
         traj.write(image)
     self.i += 1
示例#5
0
def trajToExtTraj(traj, n, *args):
    
    R, T, angle1, angle2, n1, n2, path = args
   
    path_traj   =   path + 'sphere/md_data/T=%.0f/' %T
    checkAndCreateFolder(path_traj)
    traj_ext    =   PickleTrajectory(path_traj + 'md_Ext_R%.3f.traj' %R, 'w') 
    
    for a in traj:
        c_symb  =   a.get_chemical_symbols()
        posits  =   a.positions
        atoms   =   Atoms(c_symb, positions = posits, container='Sphere')
        atoms.set_container(angle1=angle1,angle2=angle2,n1=n1,n2=n2,mode=4)
        traj_ext.write(atoms.extended_copy(n))
示例#6
0
def trajToExtTraj(traj, n, *args):
    
    R, T, angle, H, path = args
   
    path_traj   =   path + 'cylinder/md_data/T=%.0f/' %T
    checkAndCreateFolder(path_traj)
    
    traj_ext = PickleTrajectory(path_traj + 'md_Ext_R%.3f.traj' %R,'w') 
    for a in traj:
        c_symb  =   a.get_chemical_symbols()
        posits  =   a.positions
        atoms   =   Atoms(c_symb, positions = posits, container='Wedge')
        atoms.set_container(angle=angle, height=H, physical=False, pbcz=True)
        traj_ext.write(atoms.extended_copy(n))
示例#7
0
class ExtendedTrajectory:
    def __init__(self,filename,atoms,n,mode='w'):
        """
        Trajectory for multiple copies of unit cell.
        
        parameters:
        ===========
        filename:    output .traj -file
        atoms:       hotbit.Atoms object
        n:           tuple of number of symmetry operations
                     or list of tuples for the symmetry operations
        mode:        'w' write or 'a' append
        """
        self.atoms = atoms
        self.n = n
        self.ext = self.atoms.extended_copy(n)
        self.traj = PickleTrajectory(filename,mode,self.ext)

    def write(self):
        cp = self.atoms.extended_copy(self.n)
        self.ext.set_positions( cp.get_positions() )
        self.traj.write()
示例#8
0
import os
from ase import Atom, Atoms
from ase.io import PickleTrajectory

co = Atoms([Atom('C', (0, 0, 0)),
            Atom('O', (0, 0, 1.2))])
traj = PickleTrajectory('1.traj', 'w', co)
for i in range(5):
    co.positions[:, 2] += 0.1
    traj.write()
del traj
traj = PickleTrajectory('1.traj', 'a')
co = traj[-1]
print co.positions
co.positions[:] += 1
traj.write(co)
del traj
t = PickleTrajectory('1.traj', 'a')
print t[-1].positions
print '.--------'
for a in t:
    print 1, a.positions[-1,2]
co.positions[:] += 1
t.write(co)
for a in t:
    print 2, a.positions[-1,2]
assert len(t) == 7

co[0].number = 1
try:
    t.write(co)
示例#9
0
文件: info.py 项目: lqcata/ase
        return int(self.value - other.value)


if __name__ == '__main__':
    import info  # import ourselves to make info.Foo reachable

    # Create a molecule with an info attribute
    info = dict(
        creation_date='2011-06-27',
        chemical_name='Hydrogen',
        # custom classes also works provided that it is
        # imported and pickleable...
        foo=info.Foo(7),
    )
    molecule = Atoms('H2', positions=[(0., 0., 0.), (0., 0., 1.1)], info=info)
    assert molecule.info == info

    # Copy molecule
    atoms = molecule.copy()
    assert atoms.info == info

    # Save molecule to trajectory
    traj = PickleTrajectory('info.traj', 'w', atoms=molecule)
    traj.write()
    del traj

    # Load molecule from trajectory
    t = PickleTrajectory('info.traj')
    atoms = t[-1]
    assert atoms.info == info
示例#10
0
文件: hcp.py 项目: lqcata/ase
import numpy as np
from ase.io import read, PickleTrajectory
from ase.lattice import bulk
from ase.calculators.emt import EMT

a0 = 3.52 / np.sqrt(2)
c0 = np.sqrt(8 / 3.0) * a0
print '%.4f %.3f' % (a0, c0 / a0)
for i in range(3):
    traj = PickleTrajectory('Ni.traj', 'w')
    eps = 0.01
    for a in a0 * np.linspace(1 - eps, 1 + eps, 4):
        for c in c0 * np.linspace(1 - eps, 1 + eps, 4):
            ni = bulk('Ni', 'hcp', a=a, covera=c / a)
            ni.set_calculator(EMT())
            ni.get_potential_energy()
            traj.write(ni)

    configs = read('Ni.traj@:')
    energies = [config.get_potential_energy() for config in configs]
    ac = [(config.cell[0, 0], config.cell[2, 2]) for config in configs]
    from ase.optimize import polyfit
    p = polyfit(ac, energies)
    from scipy.optimize import fmin_bfgs
    a0, c0 = fmin_bfgs(p, (a0, c0))
    print '%.4f %.3f' % (a0, c0 / a0)
assert abs(a0 - 2.466) < 0.001
assert abs(c0 / a0 - 1.632) < 0.005


示例#11
0
import numpy as np

from ase.lattice import bulk
from ase.optimize import BFGS
from ase.io import PickleTrajectory
from ase.constraints import StrainFilter

from gpaw import GPAW, PW


co = bulk('Co')
co.set_initial_magnetic_moments([1.6, 1.6])
co.calc = GPAW(mode=PW(700),
               xc='PBE',
               kpts=(8, 8, 4),
               txt='co.txt')

BFGS(StrainFilter(co)).run(0.005)

a0 = co.cell[0, 0]
c0 = co.cell[2, 2]

traj = PickleTrajectory('co.traj', 'w')
eps = 0.01
for a in a0 * np.linspace(1 - eps, 1 + eps, 3):
    for c in c0 * np.linspace(1 - eps, 1 + eps, 3):
        co.set_cell(bulk('Co', a=a, covera=c / a).cell, scale_atoms=True)
        co.get_potential_energy()
        traj.write(co)
示例#12
0
        return int(self.value - other.value)


if __name__ == '__main__':
    import info  # import ourselves to make info.Foo reachable

    # Create a molecule with an info attribute
    info = dict(creation_date='2011-06-27', 
                chemical_name='Hydrogen',
                # custom classes also works provided that it is
                # imported and pickleable...
                foo=info.Foo(7),  
                )
    molecule = Atoms('H2', positions=[(0., 0., 0.), (0., 0., 1.1)], info=info)
    assert molecule.info == info

    # Copy molecule
    atoms = molecule.copy()
    assert atoms.info == info

    # Save molecule to trajectory
    traj = PickleTrajectory('info.traj', 'w', atoms=molecule)
    traj.write()
    del traj

    # Load molecule from trajectory 
    t = PickleTrajectory('info.traj')
    atoms = t[-1]
    assert atoms.info == info

示例#13
0
import numpy as np

from ase.lattice import bulk
from ase.optimize import BFGS
from ase.io import PickleTrajectory
from ase.constraints import StrainFilter

from gpaw import GPAW, PW


co = bulk("Co")
co.set_initial_magnetic_moments([1.6, 1.6])
co.calc = GPAW(mode=PW(700), xc="PBE", kpts=(8, 8, 4), txt="co.txt")

BFGS(StrainFilter(co)).run(0.005)

a0 = co.cell[0, 0]
c0 = co.cell[2, 2]

traj = PickleTrajectory("co.traj", "w")
eps = 0.01
for a in a0 * np.linspace(1 - eps, 1 + eps, 3):
    for c in c0 * np.linspace(1 - eps, 1 + eps, 3):
        co.set_cell(bulk("Co", a=a, covera=c / a).cell, scale_atoms=True)
        co.get_potential_energy()
        traj.write(co)
示例#14
0
from ase.test import NotAvailable

if sys.platform in ['win32']:
    raise NotAvailable('Fails on Windows https://trac.fysik.dtu.dk/projects/ase/ticket/62')

import os
from ase import Atom, Atoms
from ase.io import PickleTrajectory

co = Atoms([Atom('C', (0, 0, 0)),
            Atom('O', (0, 0, 1.2))])
traj = PickleTrajectory('1.traj', 'w', co)
for i in range(5):
    co.positions[:, 2] += 0.1
    traj.write()
del traj
traj = PickleTrajectory('1.traj', 'a')
co = traj[-1]
print co.positions
co.positions[:] += 1
traj.write(co)
del traj
t = PickleTrajectory('1.traj', 'a')
print t[-1].positions
print '.--------'
for a in t:
    print 1, a.positions[-1,2]
co.positions[:] += 1
t.write(co)
for a in t:
示例#15
0
atoms.get_charges = calc.notimpl

# get total energy at first ionic step
en = get_total_energy(s)
if en is not None:
    calc.set_energy(en)
else:
    print >>stderr, 'no total energy found'
    exit(3)

print(atoms)

traj = PickleTrajectory(argv[2], 'w')


traj.write(atoms)

a = s.readline()
while a != '':
    while a[:7] != 'CELL_PA' and a[:7] != 'ATOMIC_' and a != '':
        a = s.readline()
    if a == '':
        break
    if a[0] == 'A':
        coord = a.split('(')[-1]
        for i in range(natoms):
            pos[i][:] = s.readline().split()[1:4]

        if coord == 'alat)':
            atoms.set_positions(pos * alat)
        elif coord == 'bohr)':
示例#16
0
import numpy as np
from ase import Atoms
from ase.calculators.emt import EMT
from ase.io import PickleTrajectory

Cu = Atoms('Cu', pbc=(1, 0, 0), calculator=EMT())
traj = PickleTrajectory('Cu.traj', 'w')
for a in np.linspace(2.0, 4.0, 20):
    Cu.set_cell([a, 1, 1], scale_atoms=True)
    traj.write(Cu)