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


Python io.read方法代码示例

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


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

示例1: structure_to_atoms

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [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

示例2: atoms_to_structure

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [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

示例3: test_minimize

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def test_minimize(self):
        initial_structure = read('initial_mlmin.traj')
        initial_structure.set_calculator(EMT())

        initial_opt = MLMin(initial_structure,
                            trajectory='mlmin_structures.traj')
        initial_opt.run(fmax=0.01, full_output=True)

        atoms_catlearn = read('mlmin_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn)
        print('Checking number of function calls...')
        self.assertEqual(n_eval_catlearn, 7)
        print('Checking converged energy...')
        e_opt = initial_opt.list_targets[-1]
        e_test = 3.31076
        np.testing.assert_array_almost_equal(e_opt, e_test, decimal=5)
        print('Checking converged fmax...')
        fmax_opt = initial_opt.list_fmax[-1][0]
        fmax_test = 0.00816
        np.testing.assert_array_almost_equal(fmax_opt, fmax_test, decimal=5) 
开发者ID:SUNCAT-Center,项目名称:CatLearn,代码行数:22,代码来源:test_mlmin.py

示例4: testWithNumericalStressWithPBCEnabled

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def testWithNumericalStressWithPBCEnabled(self):
        filename = os.path.join(path, '../tools/generate-unit-test-expect/others/Benzene.cif')
        benzene = read(filename)
        calculator = self.model.ase()
        benzene.set_calculator(calculator)
        dyn = NPTBerendsen(benzene, timestep=0.1 * units.fs,
                           temperature=300 * units.kB,
                           taut=0.1 * 1000 * units.fs, pressure=1.01325,
                           taup=1.0 * 1000 * units.fs, compressibility=4.57e-5)

        def test_stress():
            stress = benzene.get_stress()
            numerical_stress = calculator.calculate_numerical_stress(benzene)
            diff = torch.from_numpy(stress - numerical_stress).abs().max().item()
            self.assertLess(diff, tol)
        dyn.attach(test_stress, interval=30)
        dyn.run(120) 
开发者ID:aiqm,项目名称:torchani,代码行数:19,代码来源:test_ase.py

示例5: read_posfile

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def read_posfile():
    from ase.io import read

    try:
        atoms = read('POSCAR')
    except IOError:
        print "[__main__]: Couldn't open input file POSCAR, atomic positions will not be written...\n"
        atoms = []

    return atoms

### WRITE DOS0 CONTAINING TOTAL DOS ### 
开发者ID:zhangzhengde0225,项目名称:VaspCZ,代码行数:14,代码来源:split_dos.py

示例6: read

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [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) 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:42,代码来源:__init__.py

示例7: read

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [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) 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:15,代码来源:ase_mapper.py

示例8: test_path

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def test_path(self):
        """Test ML-NEB algorithm running with an interpolated path"""
        n_images = 8
        images = [initial_structure]
        for i in range(1, n_images-1):
            image = initial_structure.copy()
            image.set_calculator(copy.deepcopy(ase_calculator))
            images.append(image)
        images.append(final_structure)

        neb = NEB(images, climb=True)
        neb.interpolate(method='linear')

        neb_catlearn = MLNEB(start=initial_structure,
                             end=final_structure,
                             interpolation=images,
                             ase_calc=ase_calculator,
                             restart=False
                             )

        neb_catlearn.run(fmax=0.05, trajectory='ML-NEB.traj', max_step=0.2,
                         full_output=True)

        atoms_catlearn = read('evaluated_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn) - 2

        self.assertEqual(n_eval_catlearn, 13)
        print('Checking number of function calls using 8 images...')
        np.testing.assert_array_equal(n_eval_catlearn, 13)
        max_unc = np.max(neb_catlearn.uncertainty_path)
        unc_test = 0.0468
        print('Checking uncertainty on the path (8 images):')
        np.testing.assert_array_almost_equal(max_unc, unc_test, decimal=4) 
开发者ID:SUNCAT-Center,项目名称:CatLearn,代码行数:35,代码来源:test_mlneb.py

示例9: read_OUTCAR

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def read_OUTCAR(path='OUTCAR'):
    """read time and ncores info from OUTCAR"""
    time = 0
    ncore = 0
    for line in open(path, 'r'):
        if line.rfind('running on  ') > -1:
            ncore = int(line.split()[2])
        elif line.rfind('Elapsed time ') > -1:
            time = float(line.split(':')[-1])

    return time, ncore 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:13,代码来源:Random_vasp_ase.py

示例10: single_optimize

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def single_optimize(struc, level, pstress, mode, setup):
    """single optmization"""
    struc = symmetrize_cell(struc, mode)
    struc.set_calculator(set_vasp(level, pstress, setup))
    energy = struc.get_potential_energy()
    print(energy)
    time, ncore = read_OUTCAR()
    struc = read('CONTCAR',format='vasp')
    return struc, energy, time 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:11,代码来源:vasp.py

示例11: __init__

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def __init__(self, procar, poscar, supercell_matrix, ispin=None):
        self.fname = procar
        self.supercell_matrix = supercell_matrix
        self._parse_procar(ispin=ispin)
        self.atoms = read(poscar)
        self.basis = []
        self.positions = [] 
开发者ID:romerogroup,项目名称:pyprocar,代码行数:9,代码来源:procar_unfolder.py

示例12: test_acquisition

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def test_acquisition(self):
        """Test ML-Min acquisition functions"""

        # Test acquisition lcb:
        initial_structure = read('initial_mlmin.traj')
        initial_structure.set_calculator(EMT())

        initial_opt = MLMin(initial_structure,
                            trajectory='mlmin_structures.traj')
        initial_opt.run(fmax=0.01, full_output=True, acq='lcb')

        atoms_catlearn = read('mlmin_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn)
        print('Checking number of function calls...')
        self.assertEqual(n_eval_catlearn, 7)
        print('Checking converged energy...')
        e_opt = initial_opt.list_targets[-1]
        e_test = 3.31076
        np.testing.assert_array_almost_equal(e_opt, e_test, decimal=5)
        print('Checking converged fmax...')
        fmax_opt = initial_opt.list_fmax[-1][0]
        fmax_test = 0.00816
        np.testing.assert_array_almost_equal(fmax_opt, fmax_test, decimal=5)

        # Test acquisition ucb:
        initial_structure = read('initial_mlmin.traj')
        initial_structure.set_calculator(EMT())

        initial_opt = MLMin(initial_structure,
                            trajectory='mlmin_structures.traj')
        initial_opt.run(fmax=0.01, full_output=True, acq='ucb')

        atoms_catlearn = read('mlmin_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn)
        print('Checking number of function calls...')
        self.assertEqual(n_eval_catlearn, 7)
        print('Checking converged energy...')
        e_opt = initial_opt.list_targets[-1]
        e_test = 3.31076
        np.testing.assert_array_almost_equal(e_opt, e_test, decimal=5)
        print('Checking converged fmax...')
        fmax_opt = initial_opt.list_fmax[-1][0]
        fmax_test = 0.00782
        np.testing.assert_array_almost_equal(fmax_opt, fmax_test, decimal=5) 
开发者ID:SUNCAT-Center,项目名称:CatLearn,代码行数:46,代码来源:test_mlmin.py

示例13: test_kernel

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def test_kernel(self):
        """Test ML-Min kernels"""

        # Test kernel ARD fixed:
        initial_structure = read('initial_mlmin.traj')
        initial_structure.set_calculator(EMT())

        initial_opt = MLMin(initial_structure,
                            trajectory='mlmin_structures.traj')
        initial_opt.run(fmax=0.01, full_output=True, acq='min_energy',
                        kernel='SQE_fixed')

        atoms_catlearn = read('mlmin_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn)
        print('Checking number of function calls...')
        self.assertEqual(n_eval_catlearn, 7)
        print('Checking converged energy...')
        e_opt = initial_opt.list_targets[-1]
        e_test = 3.31076
        np.testing.assert_array_almost_equal(e_opt, e_test, decimal=5)
        print('Checking converged fmax...')
        fmax_opt = initial_opt.list_fmax[-1][0]
        fmax_test = 0.00786
        np.testing.assert_array_almost_equal(fmax_opt, fmax_test, decimal=5)

        # Test ARD SQE kernel:
        initial_structure = read('initial_mlmin.traj')
        initial_structure.set_calculator(EMT())

        initial_opt = MLMin(initial_structure,
                            trajectory='mlmin_structures.traj')
        initial_opt.run(fmax=0.01, full_output=True, acq='min_energy',
                        kernel='ARD_SQE')

        atoms_catlearn = read('mlmin_structures.traj', ':')
        n_eval_catlearn = len(atoms_catlearn)
        print('Checking number of function calls...')
        self.assertEqual(n_eval_catlearn, 7)
        print('Checking converged energy...')
        e_opt = initial_opt.list_targets[-1]
        e_test = 3.31076
        np.testing.assert_array_almost_equal(e_opt, e_test, decimal=5)
        print('Checking converged fmax...')
        fmax_opt = initial_opt.list_fmax[-1][0]
        fmax_test = 0.00766
        np.testing.assert_array_almost_equal(fmax_opt, fmax_test, decimal=5) 
开发者ID:SUNCAT-Center,项目名称:CatLearn,代码行数:48,代码来源:test_mlmin.py

示例14: optimize

# 需要导入模块: from ase import io [as 别名]
# 或者: from ase.io import read [as 别名]
def optimize(struc, dir1):
    os.mkdir(dir1)
    os.chdir(dir1)
    time0 = 0
    # Step1: ISIF = 2
    struc.set_calculator(set_vasp(level=0, pstress=pstress)) #, setup=setup))
    print(struc.get_potential_energy())
    time, ncore = read_OUTCAR()
    time0 += time
    print('time for vasp calcs0 (seconds):  ', time)

    # Step2: ISIF = 3
    struc = read('CONTCAR',format='vasp')
    struc.set_calculator(set_vasp(level=1, pstress=pstress)) #, setup=setup))
    print(struc.get_potential_energy())
    time, ncore = read_OUTCAR()
    time0 += time
    print('time for vasp calcs1 (seconds):  ', time)

    # Step3: ISIF = 3 with high precision 
    struc = read('CONTCAR',format='vasp')
    if good_lattice(struc):
        struc = symmetrize_cell(struc, mode='C')
        struc.set_calculator(set_vasp(level=2, pstress=pstress)) #, setup=setup))
        print(struc.get_potential_energy())
        time, ncore = read_OUTCAR()
        time0 += time
        print('time for vasp calcs2 (seconds):  ', time)
        struc = read('CONTCAR',format='vasp')

        if good_lattice(struc):
            struc = symmetrize_cell(struc, mode='P')
            struc.set_calculator(set_vasp(level=3, pstress=pstress, setup=setup))
            print(struc.get_potential_energy())
            time, ncore = read_OUTCAR()
            time0 += time
            print('time for vasp calcs3 (seconds):  ', time)
            struc = read('CONTCAR',format='vasp')
           
            if good_lattice(struc):
                struc = symmetrize_cell(struc, mode='P')
                struc.set_calculator(set_vasp(level=4, pstress=pstress, setup=setup))
                struc.get_potential_energy()
                time, ncore = read_OUTCAR()
                print('time for vasp calcs4 (seconds):  ', time)
                time0 += time
                result = vasprun().values
                spg = get_symmetry_dataset(struc, symprec=5e-2)['international']
                print('#####%-10s %-10s %12.6f %6.2f %8.2f %4d %12s' % 
                (dir1, struc.get_chemical_formula(), result['calculation']['energy_per_atom'], result['gap'], time0, ncore, spg)) 
开发者ID:qzhu2017,项目名称:PyXtal,代码行数:52,代码来源:Random_vasp_ase.py


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