Пример #1
0
def make_struc():   
    slab_ideal=fcc110('Au',size=(4,2,8), a=4.163737636, vacuum=20)
    #slab_ideal=fcc110('Au',size=(4,8,i), vacuum=20)
    write('slab_ideal.struct',slab_ideal)
    slab_ideal.edit()
    #natoms_100=(len(slab_100.numbers))
    #print ('positions',slab_ideal.positions)
    natoms_ideal=len(slab_ideal.positions)
    #print(natoms_ideal)
    struc_ideal=Struc(ase2struc(slab_ideal))
    return natoms_ideal,struc_ideal
Пример #2
0
def test_analyse_comparing_bond_lengths():
    import numpy as np
    from ase.build import fcc111, fcc110
    from carmm.analyse.bonds import comparing_bonds_lengths

    # Build some models
    atoms1 = fcc111('Pd', (2, 2, 1), vacuum=20.0)
    atoms2 = fcc110('Pd', (2, 2, 1), vacuum=20.0)

    difference = comparing_bonds_lengths(atoms1, atoms2)

    # Assertion test
    assert (1e-5 > difference[np.argmax(difference)] - 2.013612)
Пример #3
0
def generate_data():
    """Generates atomic images for tests."""
    atoms = fcc110('Pt', (2, 2, 1), vacuum=7.)
    atoms[0].symbol = 'Cu'
    del atoms[3]
    atoms.set_calculator(EMT())
    atoms.get_potential_energy()
    atoms.get_forces()
    newatoms = atoms.copy()
    newatoms.set_calculator(EMT())
    newatoms[0].position += (0.27, -0.11, 0.3)
    newatoms[1].position += (0.12, 0.03, -0.22)
    newatoms.get_potential_energy()
    newatoms.get_forces()
    return [atoms, newatoms]
Пример #4
0
def generate_data(count, filename='training.traj'):
    """Generates test or training data with a simple MD simulation."""
    if os.path.exists(filename):
        return
    traj = ase.io.Trajectory(filename, 'w')
    atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
    atoms.extend(Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                        Atom('Cu', atoms[7].position + (0., 0., 5.))]))
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    atoms.set_calculator(EMT())
    atoms.get_potential_energy()
    traj.write(atoms)
    MaxwellBoltzmannDistribution(atoms, 300. * units.kB)
    dyn = VelocityVerlet(atoms, dt=1. * units.fs)
    for step in range(count - 1):
        dyn.run(50)
        traj.write(atoms)
def make_struc(i):
    slab_ideal = fcc110('Au', size=(16, 16, 40), a=4.0800000183054, vacuum=i)
    #slab_ideal=fcc110('Au',size=(4,8,i), vacuum=20)
    write('slab_ideal.struct', slab_ideal)
    #slab_ideal.edit()
    #natoms_100=(len(slab_100.numbers))
    list_z = [
        slab_ideal.positions[i][2] for i in range(len(slab_ideal.positions))
    ]
    min_z = min(list_z)
    list_x_top_row = []
    for i in range(len(slab_ideal.positions)):
        if slab_ideal.positions[i][2] == min_z:
            list_x_top_row.append(slab_ideal.positions[i][0])
    list_x_top_row_concise = list(set(list_x_top_row))
    list_x_top_row_concise.sort()
    select_list_x = list_x_top_row_concise[
        1::2]  #this slices list_x_top_row_concise using even index
    atoms_to_delete = []
    atoms_to_delete_index = []
    for i in range(len(slab_ideal.positions)):
        if slab_ideal.positions[i][
                0] in select_list_x and slab_ideal.positions[i][2] == min_z:
            atoms_to_delete.append(slab_ideal.positions[i])
            atoms_to_delete_index.append(i)
    atoms_to_delete_index.sort()
    atoms_to_delete_index.reverse()
    #to delete atoms in slab to create the 1*2 missing row reconstruction
    for i in atoms_to_delete_index:
        slab_ideal.pop(i)
    #slab_ideal.edit()
    #print('list of atoms is',slab_ideal.positions)
    #print('list_x_top_row',list_x_top_row)
    #print('list_x_top_row_concise',list_x_top_row_concise)
    #print ('min z is',min_z)
    #print('select_list_x',select_list_x)
    #print('atoms_to_delete',atoms_to_delete)
    print('atoms_to_delete_index', atoms_to_delete_index)
    natoms_ideal = len(slab_ideal.positions)
    print('number of atoms left', natoms_ideal)
    struc_ideal = Struc(ase2struc(slab_ideal))
    return natoms_ideal, struc_ideal
Пример #6
0
def generate_data(count):
    """Generates test or training data with a simple MD simulation."""
    atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
    adsorbate = Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                       Atom('Cu', atoms[7].position + (0., 0., 5.))])
    atoms.extend(adsorbate)
    atoms.set_constraint(FixAtoms(indices=[0, 2]))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 300. * units.kB)
    dyn = VelocityVerlet(atoms, dt=1. * units.fs)
    newatoms = atoms.copy()
    newatoms.set_calculator(EMT())
    newatoms.get_potential_energy()
    images = [newatoms]
    for step in range(count - 1):
        dyn.run(50)
        newatoms = atoms.copy()
        newatoms.set_calculator(EMT())
        newatoms.get_potential_energy()
        images.append(newatoms)
    return images
Пример #7
0
"""
根据 ASE tutorial Constrained minima hopping (global optimization)修改而来
"""

from ase import Atoms, Atom
from ase.build import fcc110
from ase.optimize import BFGS
from ase.calculators.emt import EMT
from ase.constraints import FixAtoms
from scan_ts.constraints import FixAtomsCom, FixAtomsComXY
import numpy as np

# Make the Pt 110 slab.
atoms = fcc110('Pt', (2, 2, 2), vacuum=7., periodic=True)

# Add the Cu2 adsorbate.
adsorbate = Atoms([
    Atom('Cu', atoms[7].position + (0., 0., 2.5)),
    Atom('Cu', atoms[7].position + (0.5, 0.5, 4.5))
])
atoms.extend(adsorbate)
atoms.write('init.cif')
# 输出初始结构 COM
index = [atom.index for atom in atoms if atom.symbol == 'Cu']
masses = atoms.get_masses()[index]
com_init = np.dot(masses, atoms.positions[index]) / masses.sum()

# Constrain the surface to be fixed and a FixAtomsCom or FixAtomsComXY constraint between
# the adsorbate atoms.
constraints = [
    FixAtoms(indices=[atom.index for atom in atoms if atom.symbol == 'Pt']),
Пример #8
0
def test_hookean():
    """
    Test of Hookean constraint.

    Checks for activity in keeping a bond, preventing vaporization, and
    that energy is conserved in NVE dynamics.
    """

    import numpy as np
    from ase import Atoms, Atom
    from ase.build import fcc110
    from ase.calculators.emt import EMT
    from ase.constraints import FixAtoms, Hookean
    from ase.md import VelocityVerlet
    from ase import units

    class SaveEnergy:
        """Class to save energy."""
        def __init__(self, atoms):
            self.atoms = atoms
            self.energies = []

        def __call__(self):
            self.energies.append(atoms.get_total_energy())

    # Make Pt 110 slab with Cu2 adsorbate.
    atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
    adsorbate = Atoms([
        Atom('Cu', atoms[7].position + (0., 0., 2.5)),
        Atom('Cu', atoms[7].position + (0., 0., 5.0))
    ])
    atoms.extend(adsorbate)
    calc = EMT()
    atoms.calc = calc

    # Constrain the surface to be fixed and a Hookean constraint between
    # the adsorbate atoms.
    constraints = [
        FixAtoms(indices=[atom.index for atom in atoms
                          if atom.symbol == 'Pt']),
        Hookean(a1=8, a2=9, rt=2.6, k=15.),
        Hookean(a1=8, a2=(0., 0., 1., -15.), k=15.)
    ]
    atoms.set_constraint(constraints)

    # Give it some kinetic energy.
    momenta = atoms.get_momenta()
    momenta[9, 2] += 20.
    momenta[9, 1] += 2.
    atoms.set_momenta(momenta)

    # Propagate in Velocity Verlet (NVE).
    dyn = VelocityVerlet(atoms, timestep=1.0 * units.fs)
    energies = SaveEnergy(atoms)
    dyn.attach(energies)
    dyn.run(steps=100)

    # Test the max bond length and position.
    bondlength = np.linalg.norm(atoms[8].position - atoms[9].position)
    assert bondlength < 3.0
    assert atoms[9].z < 15.0

    # Test that energy was conserved.
    assert max(energies.energies) - min(energies.energies) < 0.01

    # Make sure that index shuffle works.
    neworder = list(range(len(atoms)))
    neworder[8] = 9  # Swap two atoms.
    neworder[9] = 8
    atoms = atoms[neworder]
    assert atoms.constraints[1].indices[0] == 9
    assert atoms.constraints[1].indices[1] == 8
    assert atoms.constraints[2].index == 9
Пример #9
0
from ase import units


class SaveEnergy:
    """Class to save energy."""

    def __init__(self, atoms):
        self.atoms = atoms
        self.energies = []

    def __call__(self):
        self.energies.append(atoms.get_total_energy())


# Make Pt 110 slab with Cu2 adsorbate.
atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
adsorbate = Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                   Atom('Cu', atoms[7].position + (0., 0., 5.0))])
atoms.extend(adsorbate)
calc = EMT()
atoms.set_calculator(calc)

# Constrain the surface to be fixed and a Hookean constraint between
# the adsorbate atoms.
constraints = [FixAtoms(indices=[atom.index for atom in atoms if
                                 atom.symbol == 'Pt']),
               Hookean(a1=8, a2=9, rt=2.6, k=15.),
               Hookean(a1=8, a2=(0., 0., 1., -15.), k=15.)]
atoms.set_constraint(constraints)

# Give it some kinetic energy.
Пример #10
0
from ase import units


class SaveEnergy:
    """Class to save energy."""

    def __init__(self, atoms):
        self.atoms = atoms
        self.energies = []

    def __call__(self):
        self.energies.append(atoms.get_total_energy())


# Make Pt 110 slab with Cu2 adsorbate.
atoms = fcc110('Pt', (2, 2, 2), vacuum=7.)
adsorbate = Atoms([Atom('Cu', atoms[7].position + (0., 0., 2.5)),
                   Atom('Cu', atoms[7].position + (0., 0., 5.0))])
atoms.extend(adsorbate)
calc = EMT()
atoms.set_calculator(calc)

# Constrain the surface to be fixed and a Hookean constraint between
# the adsorbate atoms.
constraints = [FixAtoms(indices=[atom.index for atom in atoms if
                                 atom.symbol == 'Pt']),
               Hookean(a1=8, a2=9, rt=2.6, k=15.),
               Hookean(a1=8, a2=(0., 0., 1., -15.), k=15.)]
atoms.set_constraint(constraints)

# Give it some kinetic energy.
Пример #11
0
def get_example_slab(adsorbate=False, type="CO2", surface="111"):
    '''
    Example model generation to show tool functionality
    Parameters:

    adsorbate: Boolean
        Whether or not to include an adsorbate CO2 on the surface
    type: str
        Two adsorbate types - "CO2" and "2Cu". CO2 behaviour during optimisation
        is unrealistic in EMT.
    surface: string
        The surface facet to return
    '''
    from math import sqrt
    from ase.build import molecule, add_adsorbate, fcc111

    #### Traditional ASE functionality #####
    element = 'Au'
    lattice_parameter = 2.939
    width = 3
    depth = 2
    vacuum = 10.0

    # Create surface
    if surface == "111":
        from ase.build import fcc111
        slab = fcc111(element,
                      a=lattice_parameter * sqrt(2),
                      size=(width, width, depth),
                      vacuum=vacuum)
    elif surface == "100":
        from ase.build import fcc100
        slab = fcc100(element,
                      a=lattice_parameter * sqrt(2),
                      size=(width, width, depth),
                      vacuum=vacuum)
    elif surface == "110":
        from ase.build import fcc110
        slab = fcc110(element,
                      a=lattice_parameter * sqrt(2),
                      size=(width, width, depth),
                      vacuum=vacuum)
    else:
        raise NotImplementedError("The surface facet requested (" + surface +
                                  ") is not available")

    # Put adsorbate on the surface
    if adsorbate:
        if type == "CO2":
            position = (slab[17].position[0], slab[17].position[1])
        elif type == "2Cu":
            position = (slab[5].x, slab[5].y)

        species = get_example_adsorbate(type)
        add_adsorbate(slab, species, 3.0, position=position)

    # Make the model a bit more technically complete - include a calculator.
    from ase.calculators.emt import EMT
    slab.calc = EMT()

    return slab