当前位置: 首页>>代码示例>>Python>>正文


Python ase.Atoms方法代码示例

本文整理汇总了Python中ase.Atoms方法的典型用法代码示例。如果您正苦于以下问题:Python ase.Atoms方法的具体用法?Python ase.Atoms怎么用?Python ase.Atoms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ase的用法示例。


在下文中一共展示了ase.Atoms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: atoms_to_structure

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def atoms_to_structure(atoms):
    """
    Convert a qmpy.Structure to an ase.Atoms

    Example::

        >>> import qmpy.io.ase_mapper
        >>> atoms = ase.io.read('POSCAR')
        >>> structure = qmpy.io.ase_mapper.atoms_to_structure(atoms)

    """
    if not qmpy.FOUND_ASE:
        print 'ASE must be installed to convert Atoms object to a Structure'
        return
    struct = Structure()
    struct.cell = atoms.get_cell()
    for a in atoms: 
        atom = Atom()
        atom.coord = a.position
        atom.symbol = a.symbol
        atom.magmom = a.magmom
        atom.direct = False
        struct.add_atom(atom)
    return struct 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:26,代码来源:ase_mapper.py

示例2: to_ase_structure

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def to_ase_structure(self):
        '''
        convert System to ASE Atom obj

        '''
        structures=[]
        try:
           from ase import Atoms
        except:
           raise ImportError('No module ase.Atoms')

        for system in self.to_list():
            species=[]
            for name,numb in zip(system.data['atom_names'],system.data['atom_numbs']):
                species.extend([name]*numb)
            structure=Atoms(symbols=species,positions=system.data['coords'][0],pbc=True,cell=system.data['cells'][0])
            structures.append(structure)
        return structures 
开发者ID:deepmodeling,项目名称:dpdata,代码行数:20,代码来源:system.py

示例3: structure_to_atoms

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def structure_to_atoms(structure):
    """
    Convert a qmpy.Structure to an ase.Atoms

    Example::

        >>> import qmpy.io as io
        >>> structure = io.read('POSCAR')
        >>> atoms = io.ase_mapper.structure_to_atoms(structure)

    """
    if not qmpy.FOUND_ASE:
        print 'ASE must be installed to convert a Structure to an Atoms object'
        return
    atoms = ase.Atoms(
            structure.name,
            cell=structure.cell,
            scaled_positions=structure.coords, 
            magmoms=structure.magmoms)
    return atoms 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:22,代码来源:ase_mapper.py

示例4: _fromdict

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def _fromdict(self, atoms_dict):
        atoms_dict_copy = copy.deepcopy(atoms_dict)
        if "calculator" in atoms_dict_copy.keys():
            calculator_dict = atoms_dict_copy["calculator"]
            calculator_class = calculator_dict["calculator_class"]
            del calculator_dict["calculator_class"]
            atoms_dict_copy["calculator"] = self._dict2calculator(
                calculator_class, calculator_dict
            )
        if "constraint" in atoms_dict_copy.keys():
            atoms_dict_copy["constraint"] = [
                dict2constraint(const_dict)
                for const_dict in atoms_dict_copy["constraint"]
            ]
        atoms_dict_copy["cell"] = self._cellfromdict(celldict=atoms_dict_copy["cell"])
        atoms = Atoms(**atoms_dict_copy)
        if atoms.calc is not None:
            atoms.calc.read(atoms.calc.label)
        return atoms 
开发者ID:pyiron,项目名称:pyiron,代码行数:21,代码来源:pyiron_ase.py

示例5: __init__

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def __init__(self, images=None):
        """Store the properties of the databases being loaded as
        as needed.

        Parameters
        ----------
        images : list
            Atoms objects to generate fingerprints for.
        """
        if isinstance(images, ase.Atoms):
            images = [images]
        self._images = images

        self._data = None
        self._slab_d_data = None
        self._bulk_d_data = None
        self._mendeleev_data = None 
开发者ID:SUNCAT-Center,项目名称:CatKit,代码行数:19,代码来源:generator.py

示例6: testRMSE

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def testRMSE(self):
        datafile = os.path.join(path, 'test_data/NeuroChemOptimized/all')
        with open(datafile, 'rb') as f:
            all_atoms = pickle.load(f)
            for atoms in all_atoms:
                # reconstructing Atoms object.
                # ASE does not support loading pickled object from older version
                atoms = Atoms(atoms.get_chemical_symbols(), positions=atoms.get_positions())
                old_coordinates = copy.deepcopy(atoms.get_positions())
                old_coordinates = torch.from_numpy(old_coordinates)
                atoms.set_calculator(self.calculator)
                opt = BFGS(atoms)
                opt.run()
                coordinates = atoms.get_positions()
                coordinates = torch.from_numpy(coordinates)
                distances = (old_coordinates - coordinates).norm(dim=1)
                rmse = distances.mean()
                self.assertLess(rmse, self.tolerance) 
开发者ID:aiqm,项目名称:torchani,代码行数:20,代码来源:test_structure_optim.py

示例7: test__make_atoms_doc_from_fwid

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def test__make_atoms_doc_from_fwid():
    '''
    This test will try to make a document from your real FireWorks
    database, not the unit testing one (because I'm too lazy). So if it
    fails, then change the ID to a FireWorks ID of a completed rocket that
    you have.
    '''
    fwid = 365912
    doc = _make_atoms_doc_from_fwid(fwid)

    # Verify that we can make atoms objects from the document
    atoms = make_atoms_from_doc(doc)
    starting_atoms = make_atoms_from_doc(doc['initial_configuration'])
    assert isinstance(atoms, ase.Atoms)
    assert isinstance(starting_atoms, ase.Atoms)

    # Check that we have some of the necessary fields
    assert 'fwname' in doc  # If we weren't patching, this would be a real comparison
    assert doc['fwid'] == fwid
    assert isinstance(doc['directory'], str)
    assert isinstance('calculation_date', str) 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:23,代码来源:atoms_test.py

示例8: test__find_atoms_docs_not_in_surface_energy_collection

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def test__find_atoms_docs_not_in_surface_energy_collection():
    docs = _find_atoms_docs_not_in_surface_energy_collection()

    # Make sure these "documents" are actually `atoms` docs that can be turned
    # into `ase.Atoms` objects
    for doc in docs:
        atoms = make_atoms_from_doc(doc)
        assert isinstance(atoms, ase.Atoms)

    # Make sure that everything we found actually isn't in our `surface_energy`
    # collection
    fwids_in_atoms = {doc['fwid'] for doc in docs}
    with get_mongo_collection('surface_energy') as collection:
        surf_docs = list(collection.find({}, {'fwids': 1, '_id': 0}))
    fwids_in_surf = {fwid for doc in surf_docs for fwid in doc['fwids']}
    assert fwids_in_atoms.isdisjoint(fwids_in_surf) 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:18,代码来源:surfaces_test.py

示例9: test__create_surface

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def test__create_surface(self):
        '''
        This is a very bad test, because it really only does a type check. We
        should probably verify that the height is correct and that the surface
        has the correct orientation. Thanks for fixing this, future programmer!
        '''
        mpid = 'mp-1018129'
        miller_indices = (0, 1, 1)
        shift = 0.5
        min_height = SLAB_SETTINGS['slab_generator_settings']['min_slab_size'],
        vasp_settings = SLAB_SETTINGS['vasp']
        task = FindSurface(mpid=mpid,
                           miller_indices=miller_indices,
                           shift=shift,
                           min_height=min_height,
                           vasp_settings=vasp_settings)
        try:
            schedule_tasks([task.requires()], local_scheduler=True)

            # Should be more than just checking type
            surface = task._create_surface()
            assert isinstance(surface, ase.Atoms)

        finally:
            clean_up_tasks() 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:27,代码来源:calculation_finders_test.py

示例10: test_get_surface_docs

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def test_get_surface_docs(extra_projections):
    '''
    Currently not testing the "filters" argument because, well, I am being lazy.
    Feel free to change that yourself.
    '''
    docs = get_surface_docs(extra_projections)

    assert len(docs) > 0
    for doc in docs:
        assert isinstance(doc['mongo_id'], ObjectId)
        assert isinstance(doc['mpid'], str)
        assert len(doc['miller']) == 3
        assert all(isinstance(miller, int) for miller in doc['miller'])
        assert isinstance(doc['shift'], (float, int))
        assert isinstance(doc['intercept'], float)
        assert isinstance(doc['intercept_uncertainty'], float)
        assert isinstance(make_atoms_from_doc(doc['thinnest_structure']), ase.Atoms)
        assert isinstance(make_atoms_from_doc(doc['thinnest_structure']['initial_configuration']), ase.Atoms)
        assert len(doc['FW_info']) == 3
        assert all(isinstance(fwid, int) for fwid in doc['FW_info'])
        if extra_projections is not None:
            for projection in extra_projections:
                assert projection in doc 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:25,代码来源:gasdb_test.py

示例11: orient_atoms_upwards

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def orient_atoms_upwards(atoms):
    '''
    Orient an `ase.Atoms` object upwards so that the normal direction of the
    surface points in the upwards z direction.

    Arg:
        atoms   An `ase.Atoms` object
    Returns:
        atoms   The same `ase.Atoms` object that was input as an argument,
                except the z-direction should be pointing upwards.
    '''
    # Work on a copy so that we don't modify the original
    atoms = atoms.copy()

    rotate(atoms,
           atoms.cell[2], (0, 0, 1),    # Point the z-direction upwards
           atoms.cell[0], (1, 0, 0),    # Point the x-direction forwards
           rotate_cell=True)
    return atoms 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:21,代码来源:atoms_operators.py

示例12: flip_atoms

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def flip_atoms(atoms):
    '''
    Flips an atoms object upside down. Normally used to flip slabs.

    Arg:
        atoms   `ase.Atoms` object
    Returns:
        atoms   The same `ase.Atoms` object that was fed as an argument,
                but flipped upside down.
    '''
    atoms = atoms.copy()

    # This is black magic wizardry to me. Good look figuring it out.
    atoms.wrap()
    atoms.rotate(180, 'x', rotate_cell=True, center='COM')
    if atoms.cell[2][2] < 0.:
        atoms.cell[2] = -atoms.cell[2]
    if np.cross(atoms.cell[0], atoms.cell[1])[2] < 0.0:
        atoms.cell[1] = -atoms.cell[1]
    atoms.wrap()

    return atoms 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:24,代码来源:atoms_operators.py

示例13: tile_atoms

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def tile_atoms(atoms, min_x, min_y):
    '''
    This function will repeat an atoms structure in the x and y direction until
    the x and y dimensions are at least as wide as the given parameters.

    Args:
        atoms   `ase.Atoms` object of the structure that you want to tile
        min_x   The minimum width you want in the x-direction (Angstroms)
        min_y   The minimum width you want in the y-direction (Angstroms)
    Returns:
        atoms_tiled     An `ase.Atoms` object that's just a tiled version of
                        the `atoms` argument.
        (nx, ny)        A 2-tuple containing integers for the number of times
                        the original atoms object was repeated in the x
                        direction and y direction, respectively.
    '''
    x_length = np.linalg.norm(atoms.cell[0])
    y_length = np.linalg.norm(atoms.cell[1])
    nx = int(math.ceil(min_x/x_length))
    ny = int(math.ceil(min_y/y_length))
    n_xyz = (nx, ny, 1)
    atoms_tiled = atoms.repeat(n_xyz)
    return atoms_tiled, (nx, ny) 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:25,代码来源:atoms_operators.py

示例14: find_max_movement

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def find_max_movement(atoms_initial, atoms_final):
    '''
    Given ase.Atoms objects, find the furthest distance that any single atom in
    a set of atoms traveled (in Angstroms)

    Args:
        initial_atoms   `ase.Atoms` of the structure in its initial state
        final_atoms     `ase.Atoms` of the structure in its final state
    Returns:
        max_movement    A float indicating the further movement of any single atom
                        before and after relaxation (in Angstroms)
    '''
    # Calculate the distances for each atom
    distances = atoms_final.positions - atoms_initial.positions

    # Reduce the distances in case atoms wrapped around (the minimum image
    # convention)
    _, movements = find_mic(distances, atoms_final.cell, atoms_final.pbc)
    max_movement = max(movements)

    return max_movement 
开发者ID:ulissigroup,项目名称:GASpy,代码行数:23,代码来源:atoms_operators.py

示例15: _get_lj_data

# 需要导入模块: import ase [as 别名]
# 或者: from ase import Atoms [as 别名]
def _get_lj_data():
    from ase.calculators.lj import LennardJones

    atoms = Atoms('H3', positions=[[0, 0, 0], [0, 1, 0], [1, 1, 0]])
    atoms.set_calculator(LennardJones(rc=5.0))
    coord, elems, e_data, f_data = [], [], [], []
    for x_a in np.linspace(-5, 0, 1000):
        atoms.positions[0, 0] = x_a
        coord.append(atoms.positions.copy())
        elems.append(atoms.numbers)
        e_data.append(atoms.get_potential_energy())
        f_data.append(atoms.get_forces())

    data = {
        'coord': np.array(coord),
        'elems': np.array(elems),
        'e_data': np.array(e_data),
        'f_data': np.array(f_data)
    }
    return data 
开发者ID:Teoroo-CMC,项目名称:PiNN,代码行数:22,代码来源:test_potential.py


注:本文中的ase.Atoms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。