本文整理汇总了Python中ase.io方法的典型用法代码示例。如果您正苦于以下问题:Python ase.io方法的具体用法?Python ase.io怎么用?Python ase.io使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ase
的用法示例。
在下文中一共展示了ase.io方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: structure_to_atoms
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [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
示例2: atoms_to_structure
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [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
示例3: get_symmetry_dataset
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def get_symmetry_dataset(self, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
symprec:
angle_tolerance:
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
lattice = np.array(self.get_cell().T, dtype="double", order="C")
positions = np.array(
self.get_scaled_positions(wrap=False), dtype="double", order="C"
)
numbers = np.array(self.get_atomic_numbers(), dtype="intc")
return spglib.get_symmetry_dataset(
cell=(lattice, positions, numbers),
symprec=symprec,
angle_tolerance=angle_tolerance,
)
示例4: refine_cell
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def refine_cell(self, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
symprec:
angle_tolerance:
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
lattice = np.array(self.get_cell().T, dtype="double", order="C")
positions = np.array(
self.get_scaled_positions(wrap=False), dtype="double", order="C"
)
numbers = np.array(self.get_atomic_numbers(), dtype="intc")
cell, coords, el = spglib.refine_cell(
cell=(lattice, positions, numbers),
symprec=symprec,
angle_tolerance=angle_tolerance,
)
return Atoms(
symbols=list(self.get_chemical_symbols()), positions=coords, cell=cell
)
示例5: write
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def write(self, filename, format=None, **kwargs):
"""
Write atoms object to a file.
see ase.io.write for formats.
kwargs are passed to ase.io.write.
Args:
filename:
format:
**kwargs:
Returns:
"""
from ase.io import write
atoms = self.copy()
atoms.arrays["positions"] = atoms.positions
write(filename, atoms, format, **kwargs)
示例6: pyiron_to_pymatgen
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def pyiron_to_pymatgen(pyiron_obj):
"""
Convert pyiron atoms object to pymatgen atoms object
Args:
pyiron_obj: pyiron atoms object
Returns:
pymatgen atoms object
"""
try:
from pymatgen.io.ase import AseAtomsAdaptor
except ImportError:
raise ValueError("PyMatGen package not yet installed")
ase_atoms = pyiron_to_ase(pyiron_obj)
_check_if_simple_atoms(atoms=ase_atoms)
return AseAtomsAdaptor().get_structure(atoms=ase_atoms, cls=None)
示例7: read
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def read(source_file, *args, **kwargs):
"""
Read an input file of various formats.
Arguments:
source_file:
The first argument is a structure file of some format.
The remaining args and kwargs are passed to the methods called to read the
structure.
If the structure name contains "cif" or "POSCAR" it will be read as one of
these formats. Failing that, the file is passed to the ASE read method, and
the returned Atoms object is then converted to a Structure.
Examples::
>>> io.read(INSTALL_PATH+'/io/files/POSCAR_FCC')
>>> io.read(INSTALL_PATH+'/io/files/fe3o4.cif')
"""
try:
if 'cif' in source_file:
return cif.read(source_file, *args, **kwargs)
elif ( 'POSCAR' in source_file or
'CONTCAR' in source_file ):
return poscar.read(source_file, *args, **kwargs)
else:
return ase.io.read(source_file, *args, **kwargs)
except:
try:
return poscar.read(source_file, *args, **kwargs)
except Exception:
pass
try:
return cif.read(source_file, *args, **kwargs)
except Exception:
pass
raise FormatNotSupportedError('The file %s is in an unrecognized format\
and cannot be read' % source_file)
示例8: read
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def read(filename, **kwargs):
"""
Uses the ase.io.read method to read in a file, and convert it to a
qmpy.Structure object. Passes any optional keyword arguments to the
ase.io.read call.
"""
if not qmpy.FOUND_ASE:
print 'ASE must be installed to convert Atoms object to a Structure'
return
atoms = ase.io.read(filename, **kwargs)
return atoms_to_structure(atoms)
示例9: get_spacegroup
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def get_spacegroup(self, symprec=1e-5, angle_tolerance=-1.0):
"""
Args:
symprec:
angle_tolerance:
Returns:
https://atztogo.github.io/spglib/python-spglib.html
"""
lattice = np.array(self.get_cell(), dtype="double", order="C")
positions = np.array(
self.get_scaled_positions(wrap=False), dtype="double", order="C"
)
numbers = np.array(self.get_atomic_numbers(), dtype="intc")
space_group = spglib.get_spacegroup(
cell=(lattice, positions, numbers),
symprec=symprec,
angle_tolerance=angle_tolerance,
).split()
if len(space_group) == 1:
return {"Number": ast.literal_eval(space_group[0])}
else:
return {
"InternationalTableSymbol": space_group[0],
"Number": ast.literal_eval(space_group[1]),
}
示例10: setUp
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def setUp(self):
ani1x = torchani.models.ANI1x()
self.aev_computer = ani1x.aev_computer
filename = os.path.join(path, '../tools/generate-unit-test-expect/others/Benzene.cif')
benzene = ase.io.read(filename)
self.cell = torch.tensor(benzene.get_cell(complete=True)).float()
self.pbc = torch.tensor(benzene.get_pbc(), dtype=torch.bool)
species_to_tensor = torchani.utils.ChemicalSymbolsToInts(['H', 'C', 'N', 'O'])
self.species = species_to_tensor(benzene.get_chemical_symbols()).unsqueeze(0)
self.coordinates = torch.tensor(benzene.get_positions()).unsqueeze(0).float()
_, self.aev = self.aev_computer((self.species, self.coordinates), cell=self.cell, pbc=self.pbc)
self.natoms = self.aev.shape[1]
示例11: __get_final_atoms_object_with_vasp_forces
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def __get_final_atoms_object_with_vasp_forces(launch_id):
'''
This function will return an ase.Atoms object from a particular
FireWorks launch ID. It will also make sure that the ase.Atoms object
will have VASP-calculated forces attached to it.
Arg:
launch_id An integer representing the FireWorks launch ID of the
atoms object you want to get
Returns:
atoms ase.Atoms object with the VASP-calculated forces
'''
# We will be opening a temporary directory where we will unzip the
# FireWorks launch directory
fw_launch_file = (read_rc('fireworks_info.backup_directory') + '/%d.tar.gz' % launch_id)
temp_loc = __dump_file_to_tmp(fw_launch_file)
# Load the atoms object and then load the correct (DFT) forces from the
# OUTCAR/etc info
try:
atoms = ase.io.read('%s/slab_relaxed.traj' % temp_loc)
vasp2 = Vasp2(atoms, restart=True, directory=temp_loc)
vasp2.read_results()
# Clean up behind us
finally:
subprocess.call('rm -r %s' % temp_loc, shell=True)
return atoms
示例12: write
# 需要导入模块: import ase [as 别名]
# 或者: from ase import io [as 别名]
def write(structure, format='poscar', convention=None, filename=None,
**kwargs):
"""
Write the `~qmpy.Structure` object to a file or string.
Arguments:
structure: `~qmpy.Structure` object.
Keyword Arguments:
format:
If the format is "poscar" or "cif", call poscar.write or cif.write
respectively. Otherwise, converts the Structure to a
:mod:`~ase.Atoms` object and calls the :func:`ase.io.write` method
with all arguments and keywords passed to that function.
convention:
Takes three values, "primitive", "conventional" or None. If
"primitive" converts the structure to its primitive cell. If
"conventional" converts the structure to its conventional cell. If
None, writes the structure as is.
filename:
Filename to write to. If None, returns a string.
Returns:
None or a string.
"""
if convention == 'primitive':
structure.make_primitive()
elif convention == 'conventional':
structure.make_conventional()
def write_or_return(string, filename=None):
if filename is None:
return string
else:
f = open(filename, 'w')
f.write(string)
f.close()
if format == 'poscar':
return write_or_return(poscar.write(structure, **kwargs), filename)
elif format == 'cif':
return write_or_return(cif.write(structure, **kwargs), filename)
else:
return write_or_return(ase_mapper.write(structure, **kwargs), filename)