How to use the ase.Atoms 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 SINGROUP / matid / regtests / regtests.py View on Github external
def test_chemisorption(self):
        """Test the adsorption where there is sufficient distance between the
        adsorbate and the surface to distinguish between them even if they
        share the same elements.
        """
        with open("./structures/mat2d_adsorbate_unknown.json", "r") as fin:
            data = json.load(fin)
        system = Atoms(
            scaled_positions=data["positions"],
            cell=1e10*np.array(data["normalizedCell"]),
            symbols=data["labels"],
            pbc=True,
        )
        # view(system)

        classifier = Classifier()
        classification = classifier.classify(system)
        self.assertIsInstance(classification, Material2D)

        # No defects or unknown atoms, one adsorbate cluster
        adsorbates = classification.adsorbates
        interstitials = classification.interstitials
        substitutions = classification.substitutions
        vacancies = classification.vacancies
github SINGROUP / matid / regtests / regtests.py View on Github external
def test_fcc(self):
        """Test that a primitive NaCl fcc lattice is characterized correctly.
        """
        # Create the system
        cell = np.array(
            [
                [0, 2.8201, 2.8201],
                [2.8201, 0, 2.8201],
                [2.8201, 2.8201, 0]
            ]
        )
        cell[0, :] *= 1.05
        nacl = Atoms(
            symbols=["Na", "Cl"],
            scaled_positions=np.array([
                [0, 0, 0],
                [0.5, 0.5, 0.5]
            ]),
            cell=cell,
        )

        # Get the data
        data = self.get_material3d_properties(nacl)

        # Check that the data is valid
        self.assertEqual(data.space_group_number, 225)
        self.assertEqual(data.space_group_int, "Fm-3m")
        self.assertEqual(data.hall_symbol, "-F 4 2 3")
        self.assertEqual(data.hall_number, 523)
github libAtoms / matscipy / tests / neighbours.py View on Github external
def test_out_of_cell_small_cell(self):
        a = ase.Atoms('CC', positions=[[0.5, 0.5, 0.5],
                                       [1.1, 0.5, 0.5]],
                      cell=[1, 1, 1], pbc=False)
        i1, j1, r1 = neighbour_list("ijd", a, 1.1)
        a.set_cell([2, 1, 1])
        i2, j2, r2 = neighbour_list("ijd", a, 1.1)

        self.assertArrayAlmostEqual(i1, i2)
        self.assertArrayAlmostEqual(j1, j2)
        self.assertArrayAlmostEqual(r1, r2)
github libAtoms / matscipy / tests / neighbours.py View on Github external
def test_out_of_cell_large_cell(self):
        a = ase.Atoms('CC', positions=[[9.5, 0.5, 0.5],
                                       [10.1, 0.5, 0.5]],
                      cell=[10, 10, 10], pbc=False)
        i1, j1, r1 = neighbour_list("ijd", a, 1.1)
        a.set_cell([20, 10, 10])
        i2, j2, r2 = neighbour_list("ijd", a, 1.1)

        self.assertArrayAlmostEqual(i1, i2)
        self.assertArrayAlmostEqual(j1, j2)
        self.assertArrayAlmostEqual(r1, r2)
github SINGROUP / matid / matid / symmetry / symmetryanalyzer.py View on Github external
prim_cell_inv = np.linalg.inv(prim_cell)
        prim_pos = np.dot(conv_pos, prim_cell_inv)

        # Keep one occurrence for each atom that should be within the cell and
        # wrap it's position to tbe inside the primitive cell.
        conv_num = conv_system.get_atomic_numbers()
        conv_to_prim_map = self._symmetry_dataset["std_mapping_to_primitive"]
        _, inside_mask = np.unique(conv_to_prim_map, return_index=True)
        prim_pos = prim_pos[inside_mask]
        prim_num = conv_num[inside_mask]

        # Store the wyckoff letters and equivalent atoms
        prim_wyckoff = conv_wyckoff[inside_mask]
        prim_equivalent = conv_equivalent[inside_mask]

        prim_sys = Atoms(
            scaled_positions=prim_pos,
            symbols=prim_num,
            cell=prim_cell,
        )
        prim_sys.wrap(pbc=True)

        return prim_sys, prim_wyckoff, prim_equivalent
github vanceeasleaf / aces / materials / CNnp / structure.py View on Github external
def agnr(self,n,p,type):
		atoms=Atoms()
		for i in range(p):
			unit=self.zhexian(n,i,type+(1-2*type)*(i%2));
			atoms.extend(unit)			
		return atoms
github uw-cmg / MAST / MAST / structopt / moves / lattice_alteration_nn.py View on Github external
ind=indiv[0].copy()
        indc=indiv[0].copy()
    if len(indc) != 0:
        ctoff1 = [1.0 for one in ind]
        nl = NeighborList(ctoff1, bothways=True, self_interaction=False)
        nl.update(ind)
        try:
            natomsmove=random.randint(1,len(indc)/2)
        except ValueError:
            natomsmove=1
        passn=0
        for count in range(natomsmove):
            try:
                indexmv = random.choice([i for i in range(len(indc))])
                indices, offsets = nl.get_neighbors(indexmv)
                nns = Atoms()
                nns.append(ind[indexmv])
                for index, d in zip(indices,offsets):
                    index = int(index)
                    pos = ind[index].position + numpy.dot(d,ind.get_cell())
                    nns.append(Atom(symbol=ind[index].symbol, position=pos))
                dist = [nns.get_distance(0,i) for i in range(1, len(nns))]
                r = sum(dist)/len(dist)
                dir = random.choice([[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]])
                ind[indexmv].position += [i*r for i in dir]
            except:
                passn+=1
        indiv[0]=ind.copy()
    else:
        natomsmove=0
        passn=0
    Optimizer.output.write('Lattice Alteration NN Mutation performed on individual\n')
github jkitchin / dft-book / dft-scripts / script-21.py View on Github external
from ase import Atoms, Atom
from vasp import Vasp
from vasp.vasprc import VASPRC
VASPRC['queue.ppn'] = 4
co = Atoms([Atom('C', [0, 0, 0]),
            Atom('O', [1.2, 0, 0])],
           cell=(6., 6., 6.))
calc = Vasp('molecules/simple-co-n4',  # output dir
            xc='PBE',  # the exchange-correlation functional
            nbands=6,    # number of bands
            encut=350,    # planewave cutoff
            ismear=1,    # Methfessel-Paxton smearing
            sigma=0.01,  # very small smearing factor for a molecule
            atoms=co)
print('energy = {0} eV'.format(co.get_potential_energy()))
print(co.get_forces())
github vanceeasleaf / aces / materials / CNnpn / structure.py View on Github external
def zhexian(self,n,p,type):
		m=n*2+1;
		atoms=Atoms()
		for i in range(m):
			y=i*sqrt(3)/2
			x=0.5*(1+(type*2-1)*(i%2)-type)+p*1.5
			atoms.append(Atom('C',(x,y,0.0)))
		
		return atoms
github libAtoms / matscipy / matscipy / opls.py View on Github external
else:
            return None
    
    def name_value(self, aname, bname, cname, dname):
        for name in [
            (twochar(aname) + '-' + twochar(bname) + '-' +
             twochar(cname) + '-' + twochar(dname)),
            (twochar(dname) + '-' + twochar(cname) + '-' + 
             twochar(bname) + '-' + twochar(aname))]:
            if name in self.nvh:
                return name, self.nvh[name]
        return None, None



class OPLSStructure(ase.Atoms):
    default_map = {
        'BR': 'Br',
        'Be': 'Be',
        'C0': 'Ca',
        'Li': 'Li',
        'Mg': 'Mg',
        'Al': 'Al',
        'Ar': 'Ar',
        }

    def __init__(self, *args, **kwargs):
        ase.Atoms.__init__(self, *args, **kwargs)
        if len(self) == 0:
            self.types = None
        else:
            types = np.array(self.get_chemical_symbols())