當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。