コード例 #1
0
def test_class_unit():
    assert np.allclose(units.convert('J', 'J', 'J'), 1)

    assert approx(units.convert('kg', 'g')) == 1.e3
    assert approx(units.convert('eV', 'J')) == 1.60217733e-19
    assert approx(units.convert('J', 'eV')) == 1/1.60217733e-19
    assert approx(units.convert('J^2', 'eV**2')) == (1/1.60217733e-19) ** 2
    assert approx(units.convert('J/2', 'eV/2')) == (1/1.60217733e-19)
    assert approx(units.convert('J', 'eV/2')) == (1/1.60217733e-19) * 2
    assert approx(units.convert('J2', '2eV')) == (1/1.60217733e-19)
    assert approx(units.convert('J2', 'eV')) == (1/1.60217733e-19) * 2
    assert approx(units.convert('J/m', 'eV/Ang')) == unit_convert('J', 'eV') / unit_convert('m', 'Ang')
    units('J**eV', 'eV**eV')
    units('J/m', 'eV/m')
コード例 #2
0
    def _read_supercell(self):
        """ Deferred routine """

        f, l = self.step_to('unit_cell_cart', case=False)
        if not f:
            raise ValueError(
                "The unit-cell vectors could not be found in the seed-file.")

        l = self.readline()
        lines = []
        while not l.startswith('end'):
            lines.append(l)
            l = self.readline()

        # Check whether the first element is a specification of the units
        pos_unit = lines[0].split()
        if len(pos_unit) > 2:
            unit = 1.
        else:
            unit = unit_convert(pos_unit[0].capitalize(), 'Ang')
            # Remove the line with the unit...
            lines.pop(0)

        # Create the cell
        cell = np.empty([3, 3], np.float64)
        for i in [0, 1, 2]:
            cell[i, :] = [float(x) for x in lines[i].split()]

        return SuperCell(cell * unit)
    def _read_geometry(self, sc, *args, **kwargs):
        """ Defered routine """

        is_frac = True
        f, _ = self.step_to('atoms_frac', case=False)
        if not f:
            is_frac = False
            self.fh.seek(0)
            f, _ = self.step_to('atoms_cart', case=False)

        if not f:
            raise ValueError("The geometry coordinates (atoms_frac/cart) could not be found in the seed-file.")

        # Read the next line to determine the units
        unit = self.readline()
        unit = unit_convert(unit.strip().capitalize(), 'Ang')

        s = []
        xyz = []
        l = self.readline()
        while not 'end' in l:
            # Get the species and
            l = l.split()
            s.append(l[0])
            xyz.append(list(map(float, l[1:4])))
            l = self.readline()

        # Convert
        xyz = np.array(xyz, np.float64) * unit

        if is_frac:
            xyz = np.dot(sc.cell.T, xyz.T).T

        return Geometry(xyz, atom=s, sc=sc)
def test_unit_convert():
    assert approx(unit_convert('kg', 'g')) == 1.e3
    assert approx(unit_convert('eV', 'J')) == 1.60217733e-19
    assert approx(unit_convert('J', 'eV')) == 1/1.60217733e-19
    assert approx(unit_convert('J', 'eV', opts={'^': 2})) == (1/1.60217733e-19) ** 2
    assert approx(unit_convert('J', 'eV', opts={'/': 2})) == (1/1.60217733e-19) / 2
    assert approx(unit_convert('J', 'eV', opts={'*': 2})) == (1/1.60217733e-19) * 2
コード例 #5
0
from __future__ import division, print_function

# Import sile objects
from .sile import SileScaleUp
from ..sile import *

# Import the geometry object
import sisl._array as _a
from sisl import Geometry, Atom, SuperCell
from sisl.unit import unit_convert

import numpy as np

__all__ = ['refSileScaleUp', 'restartSileScaleUp']

Bohr2Ang = unit_convert('Bohr', 'Ang')
Ang2Bohr = unit_convert('Ang', 'Bohr')


class refSileScaleUp(SileScaleUp):
    """ REF file object for ScaleUp """
    @Sile_fh_open
    def read_supercell(self):
        """ Reads a supercell from the Sile """
        # 1st line is number of supercells
        nsc = _a.fromiteri(map(int, self.readline().split()[:3]))
        self.readline()  # natoms, nspecies
        self.readline()  # species
        cell = _a.fromiterd(map(float, self.readline().split()[:9]))
        # Typically ScaleUp uses very large unit-cells
        # so supercells will typically be restricted to [3, 3, 3]
コード例 #6
0
"""
Sile object for reading/writing ascii files from BigDFT
"""

from .sile import SileBigDFT
from ..sile import *

from sisl._internal import set_module
from sisl import Geometry, Atom, SuperCell
from sisl.unit import unit_convert

import numpy as np

__all__ = ['asciiSileBigDFT']

Bohr2Ang = unit_convert('Bohr', 'Ang')


@set_module("sisl.io.bigdft")
class asciiSileBigDFT(SileBigDFT):
    """ ASCII file object for BigDFT """
    def _setup(self, *args, **kwargs):
        """ Initialize for `asciiSileBigDFT` """
        self._comment = ['#', '!']

    @sile_fh_open()
    def read_geometry(self):
        """ Reads a supercell from the Sile """

        # 1st line is arbitrary
        self.readline(True)
コード例 #7
0
def test_unit_convert_f2():
    with pytest.raises(ValueError):
        unit_convert('eV', 'kg')
コード例 #8
0
def test_unit_convert_f1():
    with pytest.raises(ValueError):
        unit_convert('eV', 'megaerg')
def test_unit_convert_f2():
    unit_convert('eV', 'kg')
def test_unit_convert_f1():
    unit_convert('eV', 'megaerg')
コード例 #11
0
ファイル: cube.py プロジェクト: sofiasanz/sisl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import numpy as np

# Import sile objects
from sisl.io.sile import *

from sisl._internal import set_module
from sisl import Geometry, Atom, SuperCell, Grid, SislError
from sisl.unit import unit_convert

__all__ = ['cubeSile']

Ang2Bohr = unit_convert('Ang', 'Bohr')


@set_module("sisl.io")
class cubeSile(Sile):
    """ CUBE file object """
    @sile_fh_open()
    def write_supercell(self,
                        sc,
                        fmt='15.10e',
                        size=None,
                        origin=None,
                        *args,
                        **kwargs):
        """ Writes `SuperCell` object attached to this grid

        Parameters