Example #1
0
def MakeAtoms(elem1, elem2=None):
    if elem2 is None:
        elem2 = elem1
    a1 = reference_states[elem1]['a']
    a2 = reference_states[elem2]['a']
    a0 = (0.5 * a1**3 + 0.5 * a2**3)**(1.0/3.0) * 1.03
    if ismaster:
        # 50*50*50 would be big enough, but some vacancies are nice.
        print "Z1 = %i,  Z2 = %i,  a0 = %.5f" % (elem1, elem2, a0)
        atoms = FaceCenteredCubic(symbol='Cu', size=(51,51,51))
        nremove = len(atoms) - 500000
        assert nremove > 0
        remove = np.random.choice(len(atoms), nremove, replace=False)
        del atoms[remove]
        if isparallel:
            atoms = atoms.repeat(cpuLayout)
        if elem1 != elem2:
            z = atoms.get_atomic_numbers()
            z[np.random.choice(len(atoms), len(atoms)/2, replace=False)] = elem2
            atoms.set_atomic_numbers(z)
    else:
        atoms = None
    if isparallel:
        atoms = MakeParallelAtoms(atoms, cpuLayout)
    MaxwellBoltzmannDistribution(atoms, T * units.kB)
    return atoms
Example #2
0
def MakeAtoms(elem1, elem2=None):
    if elem2 is None:
        elem2 = elem1
    a1 = reference_states[elem1]['a']
    a2 = reference_states[elem2]['a']
    a0 = (0.5 * a1**3 + 0.5 * a2**3)**(1.0 / 3.0) * 1.03
    if ismaster:
        print "Z1 = %i,  Z2 = %i,  a0 = %.5f" % (elem1, elem2, a0)
    # 50*50*50 would be big enough, but some vacancies are nice.
    atoms = FaceCenteredCubic(symbol='Cu', size=(51, 51, 51))
    nremove = len(atoms) - 500000
    assert nremove > 0
    remove = np.random.choice(len(atoms), nremove, replace=False)
    del atoms[remove]
    if elem1 != elem2:
        z = atoms.get_atomic_numbers()
        z[np.random.choice(len(atoms), len(atoms) / 2, replace=False)] = elem2
        atoms.set_atomic_numbers(z)
    if isparallel:
        # Move this contribution into position
        uc = atoms.get_cell()
        x = mpi.world.rank % cpuLayout[0]
        y = (mpi.world.rank // cpuLayout[0]) % cpuLayout[1]
        z = mpi.world.rank // (cpuLayout[0] * cpuLayout[1])
        assert (0 <= x < cpuLayout[0])
        assert (0 <= y < cpuLayout[1])
        assert (0 <= z < cpuLayout[2])
        offset = x * uc[0] + y * uc[1] + z * uc[2]
        new_uc = cpuLayout[0] * uc[0] + cpuLayout[1] * uc[1] + cpuLayout[
            2] * uc[2]
        atoms.set_cell(new_uc, scale_atoms=False)
        atoms.set_positions(atoms.get_positions() + offset)
        # Distribute atoms. Maybe they are all on the wrong cpu, but that will
        # be taken care of.
        atoms = MakeParallelAtoms(atoms, cpuLayout)
    MaxwellBoltzmannDistribution(atoms, T * units.kB)
    return atoms
Example #3
0
def MakeAtoms(elem1, elem2=None):
    if elem2 is None:
        elem2 = elem1
    a1 = reference_states[elem1]['a']
    a2 = reference_states[elem2]['a']
    a0 = (0.5 * a1**3 + 0.5 * a2**3)**(1.0/3.0) * 1.03
    if ismaster:
        print "Z1 = %i,  Z2 = %i,  a0 = %.5f" % (elem1, elem2, a0)
    # 50*50*50 would be big enough, but some vacancies are nice.
    atoms = FaceCenteredCubic(symbol='Cu', size=(51,51,51))
    nremove = len(atoms) - 500000
    assert nremove > 0
    remove = np.random.choice(len(atoms), nremove, replace=False)
    del atoms[remove]
    if elem1 != elem2:
        z = atoms.get_atomic_numbers()
        z[np.random.choice(len(atoms), len(atoms)/2, replace=False)] = elem2
        atoms.set_atomic_numbers(z)
    if isparallel:
        # Move this contribution into position
        uc = atoms.get_cell()
        x = mpi.world.rank % cpuLayout[0]
        y = (mpi.world.rank // cpuLayout[0]) % cpuLayout[1]
        z = mpi.world.rank // (cpuLayout[0] * cpuLayout[1])
        assert(0 <= x < cpuLayout[0])
        assert(0 <= y < cpuLayout[1])
        assert(0 <= z < cpuLayout[2])
        offset = x * uc[0] + y * uc[1] + z * uc[2]
        new_uc = cpuLayout[0] * uc[0] + cpuLayout[1] * uc[1] + cpuLayout[2] * uc[2]
        atoms.set_cell(new_uc, scale_atoms=False)
        atoms.set_positions(atoms.get_positions() + offset)
        # Distribute atoms. Maybe they are all on the wrong cpu, but that will
        # be taken care of.
        atoms = MakeParallelAtoms(atoms, cpuLayout)
    MaxwellBoltzmannDistribution(atoms, T * units.kB)
    return atoms
Example #4
0
            print "  Periodic boundary conditions: %s" % (str(v),)
        elif k == 'natoms':
            print "  Number of atoms: %i" % (v,)
        elif hasattr(v, 'shape'):
            print "  %s: shape = %s, type = %s" % (k, str(v.shape), str(v.dtype))
        else:
            print "  %s: %s" % (k, str(v))
    # Read info from separate files.
    for k, v in metadata['datatypes'].items():
        if v and not k in small:
            info = backend.read_info(frame, k)
            if info and isinstance(info[0], tuple):
                shape, dtype = info
            else:
                shape = info
                dtype = 'unknown'
            print "  %s: shape = %s, type = %s" % (k, str(shape), dtype)
                
            
            
if __name__ == '__main__':
    from ase.lattice.cubic import FaceCenteredCubic
    from ase.io import read, write
    atoms = FaceCenteredCubic(size=(5, 5, 5), symbol='Au')
    write('test.bundle', atoms)
    atoms2 = read('test.bundle')
    assert (atoms.get_positions() == atoms2.get_positions()).all()
    assert (atoms.get_atomic_numbers() == atoms2.get_atomic_numbers()).all()
    
    
Example #5
0
    def __init__(self,
                 symbol=None,
                 layers=None,
                 positions=None,
                 latticeconstant=None,
                 symmetry=None,
                 cell=None,
                 center=None,
                 multiplicity=1,
                 filename=None,
                 debug=0):

        self.debug = debug
        self.multiplicity = multiplicity

        if filename is not None:
            # We skip MonteCarloAtoms.__init__, do it manually.
            self.mc_optim = np.zeros(101, np.intc)
            self.mc_optim[0] = 10000  # MC optim invalid
            self.read(filename)
            return

        #Find the atomic number
        if symbol is not None:
            if isinstance(symbol, str):
                self.atomic_number = atomic_numbers[symbol]
            else:
                self.atomic_number = symbol
        else:
            raise Warning('You must specify a atomic symbol or number!')

        #Find the crystal structure
        if symmetry is not None:
            if symmetry.lower() in ['bcc', 'fcc', 'hcp']:
                self.symmetry = symmetry.lower()
            else:
                raise Warning('The %s symmetry does not exist!' %
                              symmetry.lower())
        else:
            self.symmetry = reference_states[
                self.atomic_number]['symmetry'].lower()

        if self.debug:
            print 'Crystal structure:', self.symmetry

        #Find the lattice constant
        if latticeconstant is None:
            if self.symmetry == 'fcc':
                self.lattice_constant = reference_states[
                    self.atomic_number]['a']
            else:
                raise Warning(('Cannot find the lattice constant ' +
                               'for a %s structure!' % self.symmetry))
        else:
            self.lattice_constant = latticeconstant

        if self.debug:
            print 'Lattice constant(s):', self.lattice_constant

        #Make the cluster of atoms
        if layers is not None and positions is None:
            layers = list(layers)

            #Make base crystal based on the found symmetry
            if self.symmetry == 'fcc':
                if len(layers) != data.lattice[self.symmetry]['surface_count']:
                    raise Warning(
                        'Something is wrong with the defined number of layers!'
                    )

                xc = int(np.ceil(layers[1] / 2.0)) + 1
                yc = int(np.ceil(layers[3] / 2.0)) + 1
                zc = int(np.ceil(layers[5] / 2.0)) + 1

                xs = xc + int(np.ceil(layers[0] / 2.0)) + 1
                ys = yc + int(np.ceil(layers[2] / 2.0)) + 1
                zs = zc + int(np.ceil(layers[4] / 2.0)) + 1

                center = np.array((xc, yc, zc)) * self.lattice_constant
                size = (xs, ys, zs)

                if self.debug:
                    print 'Base crystal size:', size
                    print 'Center cell position:', center

                atoms = FaceCenteredCubic(
                    symbol=symbol,
                    size=size,
                    latticeconstant=self.lattice_constant,
                    align=False)

            else:
                raise Warning(
                    ('The %s crystal structure is not' + ' supported yet.') %
                    self.symmetry)

            positions = atoms.get_positions()
            numbers = atoms.get_atomic_numbers()
            cell = atoms.get_cell()
        elif positions is not None:
            numbers = [self.atomic_number] * len(positions)
        else:
            numbers = None

        #Load the constructed atoms object into this object
        self.set_center(center)
        MonteCarloAtoms.__init__(self,
                                 numbers=numbers,
                                 positions=positions,
                                 cell=cell,
                                 pbc=False)

        #Construct the particle with the assigned surfasces
        if layers is not None:
            self.set_layers(layers)
Example #6
0
atoms2 = atoms.copy()
atoms = MonteCarloAtoms(atoms)
print "Number of atoms:", len(atoms)
# Replace 10% of the atoms with element2
newz = where(greater(random.random((len(atoms), )), 0.9), element2number,
             elementnumber)
atoms.set_atomic_numbers(newz)
atoms2.set_atomic_numbers(newz)

atoms.set_calculator(MonteCarloEMT())
atoms2.set_calculator(EMT())
atoms.get_potential_energy()

for e in ((element, elementnumber), (element2, element2number)):
    print("Number of %s atoms (Z=%d): %d" %
          (e[0], e[1], sum(equal(atoms.get_atomic_numbers(), e[1]))))

print
print "Testing perturbations of single atoms"

magnarr = array((0.0, 0.01, 0.1, 1.0, 3.0, 10.0))
numarr = array((1, 3, 10, len(atoms) / 2, -3))
pick1 = argsort(random.random((len(magnarr), )))
for magn in take(magnarr, pick1):
    pick2 = argsort(random.random((len(numarr), )))
    for number in take(numarr, pick2):
        # Pick number random atoms.
        if number < 0:
            # Find N neighboring atoms and perturb them
            number = -number
            nblist = atoms.get_calculator().get_neighborlist()
Example #7
0
b = ss[4]
assert a.index == b.index
assert a.atoms is b.atoms

a2 = Atoms(ss)
ReportTest("number of atoms in copy of subset", len(a2), 6, 0)

a = Filter(atoms, indices=(5, 6, 7, 8))
ReportTest("Number of atoms in subset", len(a), 4, 0)

a.set_atomic_numbers(47 * ones(4, int32))
ReportTest("subset: z[0]", a.get_atomic_numbers()[0], 47, 0)
ReportTest("subset: z[1]", a.get_atomic_numbers()[1], 47, 0)
ReportTest("subset: z[2]", a.get_atomic_numbers()[2], 47, 0)
ReportTest("subset: z[3]", a.get_atomic_numbers()[3], 47, 0)
z = atoms.get_atomic_numbers()
ReportTest("full: z[0]", z[0], 29, 0)
ReportTest("full: z[4]", z[4], 29, 0)
ReportTest("full: z[5]", z[5], 47, 0)
ReportTest("full: z[8]", z[8], 47, 0)
ReportTest("full: z[9]", z[9], 29, 0)
ReportTest("full: z[100]", z[100], 29, 0)

r = a.get_positions()
r[2] = array([10.0, 20.0, 30.0])
a.set_positions(r)

r = atoms.get_positions()
ReportTest("full: r[7,0]", r[7, 0], 10.0, 0)
ReportTest("full: r[7,1]", r[7, 1], 20.0, 0)
ReportTest("full: r[7,2]", r[7, 2], 30.0, 0)
Example #8
0
    def __init__(self, symbol=None, layers=None, positions=None,
                 latticeconstant=None, symmetry=None, cell=None, 
                 center=None, multiplicity=1, filename=None, debug=0):

        self.debug = debug
        self.multiplicity = multiplicity

        if filename is not None:
            # We skip MonteCarloAtoms.__init__, do it manually.
            self.mc_optim = np.zeros(101, np.intc)
            self.mc_optim[0] = 10000  # MC optim invalid
            self.read(filename)
            return
        
        #Find the atomic number
        if symbol is not None:
            if isinstance(symbol, str):
                self.atomic_number = atomic_numbers[symbol]
            else:
                self.atomic_number = symbol
        else:
            raise Warning('You must specify a atomic symbol or number!')

        #Find the crystal structure
        if symmetry is not None:
            if symmetry.lower() in ['bcc', 'fcc', 'hcp']:
                self.symmetry = symmetry.lower()
            else:
                raise Warning('The %s symmetry does not exist!' % symmetry.lower())
        else:
            self.symmetry = reference_states[self.atomic_number]['symmetry'].lower()

        if self.debug:
            print 'Crystal structure:', self.symmetry

        #Find the lattice constant
        if latticeconstant is None:
            if self.symmetry == 'fcc':
                self.lattice_constant = reference_states[self.atomic_number]['a']
            else:
                raise Warning(('Cannot find the lattice constant ' +
                               'for a %s structure!' % self.symmetry))
        else:
            self.lattice_constant = latticeconstant

        if self.debug:
            print 'Lattice constant(s):', self.lattice_constant

        #Make the cluster of atoms
        if layers is not None and positions is None:
            layers = list(layers)

            #Make base crystal based on the found symmetry
            if self.symmetry == 'fcc':
                if len(layers) != data.lattice[self.symmetry]['surface_count']:
                    raise Warning('Something is wrong with the defined number of layers!')

                xc = int(np.ceil(layers[1] / 2.0)) + 1
                yc = int(np.ceil(layers[3] / 2.0)) + 1
                zc = int(np.ceil(layers[5] / 2.0)) + 1

                xs = xc + int(np.ceil(layers[0] / 2.0)) + 1
                ys = yc + int(np.ceil(layers[2] / 2.0)) + 1
                zs = zc + int(np.ceil(layers[4] / 2.0)) + 1

                center = np.array((xc, yc, zc)) * self.lattice_constant
                size = (xs, ys, zs)

                if self.debug:
                    print 'Base crystal size:', size
                    print 'Center cell position:', center

                atoms = FaceCenteredCubic(symbol=symbol,
                                          size=size,
                                          latticeconstant=self.lattice_constant,
                                          align=False)

            else:
                raise Warning(('The %s crystal structure is not' +
                               ' supported yet.') % self.symmetry)

            positions = atoms.get_positions()
            numbers = atoms.get_atomic_numbers()
            cell = atoms.get_cell()
        elif positions is not None:
            numbers = [self.atomic_number] * len(positions)
        else:
            numbers = None

        #Load the constructed atoms object into this object
        self.set_center(center)
        MonteCarloAtoms.__init__(self, numbers=numbers, positions=positions,
                                 cell=cell, pbc=False)

        #Construct the particle with the assigned surfasces
        if layers is not None:
            self.set_layers(layers)
Example #9
0
for latconst, maxrdf, nbins, withemt in testtypes:

    atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                              symbol="Cu", size=(10,10,10),
                              latticeconstant=latconst, debug=0)
    natoms = len(atoms)
    ReportTest("Number of atoms", natoms, 4000, 0)

    if withemt:
        atoms.set_calculator(EMT())
        print atoms.get_potential_energy()

    result = _asap.RawRDF(atoms, maxrdf, nbins, zeros(len(atoms), int32), 1,
                          ListOfElements(atoms))
    z = atoms.get_atomic_numbers()[0]

    globalrdf, rdfdict, countdict = result

    print globalrdf

    ReportTest("Local and global RDF are identical",
               min( globalrdf == rdfdict[0][(z,z)]), 1, 0)
    ReportTest("Atoms are counted correctly", countdict[0][z], natoms, 0)
    
    shellpop = [12, 6, 24, 12, 24, -1]
    shell = [sqrt(i+1.0)/sqrt(2.0) for i in range(6)]
    print shell
    print shellpop
    n = 0