Пример #1
0
class ConcentrationConverter(object):
    _element_data = OrderedDict(
        (e.symbol, e.atomic_weight) for e in get_all_elements())

    def __init__(self):
        self._symbols = None
        self._concentrations_at = None
        self._concentrations_wt = None

    def run(self, symbols, concentrations, mode):
        data = self._element_data

        if mode == 'at2wt':
            concentrations_at = concentrations
            concentrations_wt = [
                c * data[s] for s, c in zip(symbols, concentrations)]
        elif mode == 'wt2at':
            concentrations_wt = concentrations
            concentrations_at = [
                c / data[s] for s, c in zip(symbols, concentrations)]
        else:
            raise ValueError('Invalid mode:', mode)

        self._symbols = symbols
        self._concentrations_at = self._normalize(concentrations_at)
        self._concentrations_wt = self._normalize(concentrations_wt)

    @staticmethod
    def _normalize(concentrations):
        return np.array(concentrations) / sum(concentrations)

    def write(self, mode):
        if mode == 'at':
            weights = self._concentrations_at
        elif mode == 'wt':
            weights = self._concentrations_wt
        else:
            raise ValueError('Invalid mode:', mode)

        for symbol in self._symbols:
            print('{:16s}'.format(symbol), end='')
        print()
        for weight in weights:
            print('{:16.12f}'.format(weight), end='')
        print()

    def get_symbols(self):
        return self._symbols

    def get_concentrations_at(self):
        return self._concentrations_at

    def get_concentrations_wt(self):
        return self._concentrations_wt
Пример #2
0
    "turbomole",
    "v-sim",
    "vasp",
    "xsf",
    "xyz"]


# safe settings for non-cubic large gas phase cell
GAS_PHASE_CELL = [15, 16, 17]

atomic_radii = {
    element.symbol:
    (element.atomic_radius
     or element.covalent_radius_cordero
     or element.covalent_radius_pyykko)
    for element in mendeleev.get_all_elements()}


class MockRequest(object):

    def __init__(self, args):
        self.args = json.dumps(args)

    def __repr__(self):
        return '[MockRequest] ' + pprint.pformat(self.args)


@catKitDemo.route('/generate_bulk_cif/', methods=['GET', 'POST'])
def generate_bulk_cif(request=None, return_atoms=False):
    request = flask.request if request is None else request
    if isinstance(request.args, str):
Пример #3
0
#The MIT License (MIT)
#
#Copyright (c) 2015 Lukasz Mentel
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.

from mendeleev import get_all_elements

_elements = {x.symbol: x for x in get_all_elements()}

globals().update(_elements)

__all__ = list(_elements.keys())
Пример #4
0
    def __init__(self,
                 log_path: str = None,
                 qm_sdf: str = None,
                 mmff_sdf: str = None,
                 dipole: torch.Tensor = None,
                 prop_dict_raw: dict = None,
                 gauss_version: int = 16):
        """
        Extract information from Gaussian 16 log files OR from SDF files. In the later case, qm_sdf, dipole and
        prop_dict_raw must not be None
        :param log_path:
        :param qm_sdf:
        :param mmff_sdf:
        :param dipole:
        :param prop_dict_raw:
        """
        # for conversion of element, which is the atomic number of element
        self.gauss_version = gauss_version
        self._dipole = dipole
        from mendeleev import get_all_elements
        self._element_dict = {
            e.symbol: e.atomic_number
            for e in get_all_elements()
        }
        # self._element_dict = {'H': 1, 'B': 5, 'C': 6, 'N': 7, 'O': 8, 'F': 9, 'P': 15, 'S': 16, 'Cl': 17, 'Se': 34,
        #                       'Br': 35, 'I': 53}
        # for conversion of element_p, which is the column and period of element
        self._element_periodic = {
            e.symbol:
            [e.period, e.group.group_id if e.group is not None else None]
            for e in get_all_elements()
        }
        # self._element_periodic = {"H": [1, 1], "B": [2, 3], "C": [2, 4], "N": [2, 5], "O": [2, 6], "F": [2, 7],
        #                           "P": [3, 5], "S": [3, 6], "Cl": [3, 7], "Br": [4, 7], "I": [5, 17], 'Se': [4, 16]}

        self.log_path = log_path
        self.log_lines = open(
            log_path).readlines() if log_path is not None else None
        self.normal_termination = self._normal_finishes(
        ) if qm_sdf is None else True
        if not self.normal_termination:
            print("{} did not terminate normally!!".format(log_path))
            return

        self.base_name = osp.basename(log_path).split(".")[0] \
            if log_path is not None else osp.basename(qm_sdf).split(".")[0]
        self.dir = osp.dirname(
            log_path) if log_path is not None else osp.dirname(qm_sdf)

        self.mmff_sdf = mmff_sdf
        self.mmff_lines = open(
            mmff_sdf).readlines() if mmff_sdf is not None else None
        if qm_sdf is None:
            qm_sdf = osp.join(self.dir, self.base_name + ".qm.sdf")
            if (not osp.exists(qm_sdf)) and (log_path is not None):
                os.system("obabel -ig16 {} -osdf -O {}".format(
                    log_path, qm_sdf))
        self.qm_sdf = qm_sdf
        self.qm_lines = open(qm_sdf).readlines()

        self.hartree2ev = Hartree / eV

        self.prop_dict_raw = prop_dict_raw
        if self.prop_dict_raw is None:
            self._reference = np.load(
                osp.join(osp.dirname(__file__),
                         "atomref.B3LYP_631Gd.10As.npz"))["atom_ref"]
            self.prop_dict_raw = {}
            # read properties from log file
            self._read_prop()
        # get elements from .sdf file
        self._get_elements()
        # get coordinates of the elements from .sdf file
        self._get_coordinates()
        self._charges_mulliken = None
        if log_path is not None:
            # subtract reference energy
            self._prop_ref()
Пример #5
0
import pytest
from mendeleev import Element, element, get_all_elements
from mendeleev.db import get_session

ALL_ELEMENTS = {x.symbol: x for x in get_all_elements()}
SYMBOLS = list(ALL_ELEMENTS.keys())
NAMES = [x.name for x in ALL_ELEMENTS.values()]


@pytest.fixture
def session():

    return get_session()


def test_query(session):

    si = session.query(Element).filter(Element.symbol == "Si").one()
    assert si.name == "Silicon"


def test_element():

    si = element("Si")
    assert si.name == "Silicon"


@pytest.mark.parametrize("atomic_number", list(range(1, 119)))
def test_elements_get_by_atomic_number(atomic_number):

    e = element(atomic_number)