How to use the ase.build.bulk function in ase

To help you get started, we’ve selected a few ase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SUNCAT-Center / CatKit / tests / examples.py View on Github external
def test_slab_generation():
    atoms = bulk('Pd', 'fcc', a=4, cubic=True)
    atoms[3].symbol = 'Cu'

    Gen = SlabGenerator(
        atoms,
        miller_index=[2, 1, 1],
        layers=9,
        fixed=5,
        vacuum=10,
    )

    terminations = Gen.get_unique_terminations()

    images = []
    for i, t in enumerate(terminations):
        slab = Gen.get_slab(iterm=i)
        slab.center(axis=2, vacuum=5)
github SINGROUP / dscribe / regtests / mbtr.py View on Github external
])

        triclinic_cell = desc.create(molecule)
        suce = molecule * (2, 1, 1)
        triclinic_suce = desc.create(suce)

        diff = abs(np.sum(triclinic_cell[0, :] - triclinic_suce[0, :]))
        tricl_sum = abs(np.sum(triclinic_cell[0, :]))
        self.assertTrue(diff/tricl_sum < 0.05)

        # Testing that the same crystal, but different unit cells will have a
        # similar spectrum when they are normalized. There will be small
        # differences in the shape (due to not double counting distances)
        a1 = bulk('H', 'fcc', a=2.0)
        a2 = bulk('H', 'fcc', a=2.0, orthorhombic=True)
        a3 = bulk('H', 'fcc', a=2.0, cubic=True)

        triclinic_cell = desc.create(a1)
        orthorhombic_cell = desc.create(a2)
        cubic_cell = desc.create(a3)

        diff1 = abs(np.sum(triclinic_cell[0, :] - orthorhombic_cell[0, :]))
        diff2 = abs(np.sum(triclinic_cell[0, :] - cubic_cell[0, :]))
        tricl_sum = abs(np.sum(triclinic_cell[0, :]))
        self.assertTrue(diff1/tricl_sum < 0.05)
        self.assertTrue(diff2/tricl_sum < 0.05)

        # Tests that the correct peak locations are present in a cubic periodic
        desc = MBTR(
            species=["H"],
            periodic=True,
            k3={
github SINGROUP / dscribe / examples / parallel_execution / parallel_mbtr.py View on Github external
def split(items, n):
    """
    """
    k, m = divmod(len(items), n)
    splitted = (items[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
    return splitted


if __name__ == '__main__':

    # Define a dataset
    data = {
        "NaCl": ase.build.bulk("NaCl", "rocksalt", 5.64),
        "Diamond": ase.build.bulk("C", "diamond", 3.567),
        "Al": ase.build.bulk("Al", "fcc", 4.046),
        "GaAs": ase.build.bulk("GaAs", "zincblende", 5.653),
    }
    Sample = namedtuple("Sample", "key value")
    samples = [Sample(key, value) for key, value in data.items()]
    n_samples = len(data)

    # Split the data into roughly equivalent chunks for each process. The entries
    n_proc = 4
    samples_split = split(samples, n_proc)
    id_samples_tuple = [(x[0], x[1]) for x in enumerate(samples_split)]

    # Find out the maximum number of atoms in the data. This variable is shared
    # to all the processes in the create function
    stats = dscribe.utils.system_stats(data.values())
    atomic_numbers = stats["atomic_numbers"]
    n_atoms_max = stats["n_atoms_max"]
    min_distance = stats["min_distance"]
github SINGROUP / dscribe / examples / parallel_execution / parallel_mbtr.py View on Github external
}


def split(items, n):
    """
    """
    k, m = divmod(len(items), n)
    splitted = (items[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
    return splitted


if __name__ == '__main__':

    # Define a dataset
    data = {
        "NaCl": ase.build.bulk("NaCl", "rocksalt", 5.64),
        "Diamond": ase.build.bulk("C", "diamond", 3.567),
        "Al": ase.build.bulk("Al", "fcc", 4.046),
        "GaAs": ase.build.bulk("GaAs", "zincblende", 5.653),
    }
    Sample = namedtuple("Sample", "key value")
    samples = [Sample(key, value) for key, value in data.items()]
    n_samples = len(data)

    # Split the data into roughly equivalent chunks for each process. The entries
    n_proc = 4
    samples_split = split(samples, n_proc)
    id_samples_tuple = [(x[0], x[1]) for x in enumerate(samples_split)]

    # Find out the maximum number of atoms in the data. This variable is shared
    # to all the processes in the create function
    stats = dscribe.utils.system_stats(data.values())
github rosswhitfield / ase / doc / gettingstarted / tut06_database / solution / solution.py View on Github external
from ase.db import connect
from ase.constraints import ExpCellFilter
from ase.optimize import BFGS
from ase.build import bulk
from ase.dft.bandgap import bandgap
from gpaw import GPAW, PW


if Path('database.db').is_file():
    Path('database.db').unlink()

structures = ['Si', 'Ge', 'C']
db = connect('database.db')

for f in structures:
    db.write(bulk(f))

for row in db.select():
    atoms = row.toatoms()
    calc = GPAW(mode=PW(400),
                kpts=(4, 4, 4),
                txt=f'{row.formula}-gpaw.txt', xc='LDA')
    atoms.calc = calc
    atoms.get_stress()
    filter = ExpCellFilter(atoms)
    opt = BFGS(filter)
    opt.run(fmax=0.05)
    db.write(atoms=atoms, relaxed=True)


for row in db.select(relaxed=True):
    atoms = row.toatoms()
github rosswhitfield / ase / ase / io / jsontraj.py View on Github external
def main():
    import io
    from ase.io import iread, write
    from ase.build import bulk, molecule

    images1 = [molecule('H2O'), molecule('O2'),
               bulk('Si'), bulk('Fe')]

    buf = io.StringIO()
    write(buf, images1, format='jsontraj')
    buf.seek(0)
    print(buf.getvalue())

    images2 = list(iread(buf, format='jsontraj'))

    for img1, img2 in zip(images1, images2):
        assert img1 == img2
github rosswhitfield / ase / doc / ase / calculators / dftd3_gpaw.py View on Github external
import numpy as np
from gpaw import GPAW, PW

from ase.calculators.dftd3 import DFTD3
from ase.build import bulk
from ase.constraints import UnitCellFilter

from ase.optimize import LBFGS

np.random.seed(0)

diamond = bulk('C')
diamond.rattle(stdev=0.1, seed=0)
diamond.cell += np.random.normal(scale=0.1, size=(3,3))
dft = GPAW(xc='PBE', kpts=(8,8,8), mode=PW(400))
d3 = DFTD3(dft=dft)
diamond.calc = d3

ucf = UnitCellFilter(diamond)

opt = LBFGS(ucf, logfile='diamond_opt.log', trajectory='diamond_opt.traj')
opt.run(fmax=0.05)
github pyscf / pyscf / pbc / examples / helpers.py View on Github external
def get_ase_diamond_primitive(atom='C'):
    """Get the ASE atoms for primitive (2-atom) diamond unit cell."""
    from ase.build import bulk
    if atom == 'C':
        ase_atom = bulk('C', 'diamond', a=3.5668*A2B)
    else:
        ase_atom = bulk('Si', 'diamond', a=5.431*A2B)
    return ase_atom
github libAtoms / matscipy / matscipy / dislocation.py View on Github external
def get_elastic_constants(pot_path=None,
                          calculator=None,
                          delta=1e-2,
                          symbol="W"):
    """
    return lattice parameter, and cubic elastic constants: C11, C12, 44
    using matscipy function
    pot_path - path to the potential

    symbol : string
        Symbol of the element to pass to ase.lattuce.cubic.SimpleCubicFactory
        default is "W" for tungsten
    """

    unit_cell = bulk(symbol)

    if (pot_path is not None) and (calculator is None):
        # create lammps calculator with the potential
        lammps = LAMMPSlib(lmpcmds=["pair_style eam/fs",
                           "pair_coeff * * %s W" % pot_path],
                           atom_types={'W': 1}, keep_alive=True)
        calculator = lammps

    unit_cell.set_calculator(calculator)

#   simple calculation to get the lattice constant and cohesive energy
#    alat0 = W.cell[0][1] - W.cell[0][0]
    sf = StrainFilter(unit_cell)  # or UnitCellFilter(W) -> to minimise wrt pos, cell
    opt = FIRE(sf)
    opt.run(fmax=1e-4)  # max force in eV/A
    alat = unit_cell.cell[0][1] - unit_cell.cell[0][0]
github SINGROUP / dscribe / examples / pyfunctional.py View on Github external
from dscribe.descriptors import CoulombMatrix
from dscribe.descriptors import SineMatrix
from dscribe.descriptors import EwaldMatrix

# Setup the descriptors
n_atoms_max = 4
n_proc = 4
coulombmatrix = CoulombMatrix(n_atoms_max=n_atoms_max)
sinematrix = SineMatrix(n_atoms_max=n_atoms_max)
ewaldmatrix = EwaldMatrix(n_atoms_max=n_atoms_max)

# Define a dataset
data = {
    "NaCl": ase.build.bulk("NaCl", "rocksalt", 5.64),
    "Diamond": ase.build.bulk("C", "diamond", 3.567),
    "Al": ase.build.bulk("Al", "fcc", 4.046),
    "GaAs": ase.build.bulk("GaAs", "zincblende", 5.653),
}

# Setup an iterable that runs through the samples.
Result = namedtuple("Result", "cm sm em")
Sample = namedtuple("Sample", "key value")
samples = [Sample(key, value) for key, value in data.items()]


def create_descriptors(atoms):
    """This function defines and sets up the descriptors that we are going to create.
    """
    cm = coulombmatrix.create(atoms)
    sm = sinematrix.create(atoms)
    em = ewaldmatrix.create(atoms, rcut=10, gcut=10)