File: thermo.py

package info (click to toggle)
python-mp-api 0.45.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,988 kB
  • sloc: python: 6,712; makefile: 14
file content (185 lines) | stat: -rw-r--r-- 8,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from __future__ import annotations

from emmet.core.molecules.thermo import MoleculeThermoDoc
from emmet.core.mpid import MPculeID

from mp_api.client.core import BaseRester


class MoleculesThermoRester(BaseRester[MoleculeThermoDoc]):
    suffix = "molecules/thermo"
    document_model = MoleculeThermoDoc
    primary_key = "property_id"

    def search(
        self,
        molecule_ids: MPculeID | list[MPculeID] | None = None,
        property_ids: str | list[str] | None = None,
        charge: int | None = None,
        spin_multiplicity: int | None = None,
        level_of_theory: str | None = None,
        solvent: str | None = None,
        lot_solvent: str | None = None,
        correction_level_of_theory: str | None = None,
        correction_solvent: str | None = None,
        correction_lot_solvent: str | None = None,
        combined_lot_solvent: str | None = None,
        electronic_energy: tuple[float, float] | None = None,
        zero_point_energy: tuple[float, float] | None = None,
        total_enthalpy: tuple[float, float] | None = None,
        total_entropy: tuple[float, float] | None = None,
        translational_enthalpy: tuple[float, float] | None = None,
        rotational_enthalpy: tuple[float, float] | None = None,
        vibrational_enthalpy: tuple[float, float] | None = None,
        translational_entropy: tuple[float, float] | None = None,
        rotational_entropy: tuple[float, float] | None = None,
        vibrational_entropy: tuple[float, float] | None = None,
        free_energy: tuple[float, float] | None = None,
        formula: str | list[str] | None = None,
        elements: list[str] | None = None,
        exclude_elements: list[str] | None = None,
        chemsys: str | list[str] | None = None,
        num_chunks: int | None = None,
        chunk_size: int = 1000,
        all_fields: bool = True,
        fields: list[str] | None = None,
    ):
        """Query molecules thermo docs using a variety of search criteria.

        Arguments:
            molecule_ids (MPculeID, List[MPculeID]): List of Materials Project Molecule IDs (MPculeIDs) to return data
                for.
            property_ids (str, List[str]): List of property IDs to return data for.
            charge (Tuple[int, int]): Minimum and maximum charge for the molecule.
            spin_multiplicity (Tuple[int, int]): Minimum and maximum spin for the molecule.
            level_of_theory (str): Desired level of theory (e.g. "wB97X-V/def2-TZVPPD/SMD")
            solvent (str): Desired solvent (e.g. "SOLVENT=WATER")
            lot_solvent (str): Desired combination of level of theory and solvent
                (e.g. "wB97X-V/def2-TZVPPD/SMD(SOLVENT=THF)")
            correction_level_of_theory (str): Desired correction level of theory (e.g. "wB97X-V/def2-TZVPPD/SMD")
            correction_solvent (str): Desired correction solvent (e.g. "SOLVENT=WATER")
            correction_lot_solvent (str): Desired correction combination of level of theory and solvent
                (e.g. "wB97X-V/def2-TZVPPD/SMD(SOLVENT=THF)")
            combined_lot_solvent (str): Desired combination of level of theory and solvent including both main
                thermo calculation and single-point energy correction
                (e.g. "wB97X-D/def2-SVPD/VACUUM//wB97X-V/def2-TZVPPD/SMD(SOLVENT=THF)")
            electronic_energy (Tuple[float, float]): Minimum and maximum electronic energy
            zero_point_energy (Tuple[float, float]): Minimum and maximum zero-point energy
            total_enthalpy (Tuple[float, float]): Minimum and maximum total enthalpy
            total_entropy (Tuple[float, float]): Minimum and maximum total entropy
            translational_enthalpy (Tuple[float, float]): Minimum and maximum translational enthalpy
            rotational_enthalpy (Tuple[float, float]): Minimum and maximum rotational enthalpy
            vibrational_enthalpy (Tuple[float, float]): Minimum and maximum vibrational enthalpy
            translational_entropy (Tuple[float, float]): Minimum and maximum translational enthalpy
            rotational_entropy (Tuple[float, float]): Minimum and maximum rotational enthalpy
            vibrational_entropy (Tuple[float, float]): Minimum and maximum vibrational enthalpy
            free_energy (Tuple[float, float]): Minimum and maximum free energy
            formula (str, List[str]): An alphabetical formula or list of formulas
                (e.g. "C2 Li2 O4", ["C2 H4", "C2 H6"]).
            elements (List[str]): A list of elements.
            exclude_elements (List(str)): List of elements to exclude.
            chemsys (str, List[str]): A chemical system, list of chemical systems
                (e.g., Li-C-O, [C-O-H-N, Li-N]).
            num_chunks (int): Maximum number of chunks of data to yield. None will yield all possible.
            chunk_size (int): Number of data entries per chunk.
            all_fields (bool): Whether to return all fields in the document. Defaults to True.
            fields (List[str]): List of fields in MoleculeDoc to return data for.
                Default is "molecule_id", "property_id", "solvent", "method", "last_updated"
                if all_fields is False.

        Returns:
            ([MoleculeThermoDoc]) List of molecule thermo documents
        """
        query_params = {}  # type: dict

        min_max = [
            "electronic_energy",
            "zero_point_energy",
            "total_enthalpy",
            "total_entropy",
            "translational_enthalpy",
            "rotational_enthalpy",
            "vibrational_enthalpy",
            "translational_entropy",
            "rotational_entropy",
            "vibrational_entropy",
            "free_energy",
        ]

        for param, value in locals().items():
            if param in min_max and value:
                if isinstance(value, (int, float)):
                    value = (value, value)
                query_params.update(
                    {
                        f"{param}_min": value[0],
                        f"{param}_max": value[1],
                    }
                )

        if molecule_ids:
            if isinstance(molecule_ids, str):
                molecule_ids = [molecule_ids]

            query_params.update({"molecule_ids": ",".join(molecule_ids)})

        if property_ids:
            if isinstance(property_ids, str):
                property_ids = [property_ids]

            query_params.update({"property_ids": ",".join(property_ids)})

        if charge:
            query_params.update({"charge": charge})

        if spin_multiplicity:
            query_params.update({"spin_multiplicity": spin_multiplicity})

        if level_of_theory:
            query_params.update({"level_of_theory": level_of_theory})

        if solvent:
            query_params.update({"solvent": solvent})

        if lot_solvent:
            query_params.update({"lot_solvent": lot_solvent})

        if correction_level_of_theory:
            query_params.update(
                {"correction_level_of_theory": correction_level_of_theory}
            )

        if correction_solvent:
            query_params.update({"correction_solvent": correction_solvent})

        if correction_lot_solvent:
            query_params.update({"correction_lot_solvent": correction_lot_solvent})

        if combined_lot_solvent:
            query_params.update({"combined_lot_solvent": combined_lot_solvent})

        if formula:
            if isinstance(formula, str):
                formula = [formula]

            query_params.update({"formula": ",".join(formula)})

        if chemsys:
            if isinstance(chemsys, str):
                chemsys = [chemsys]

            query_params.update({"chemsys": ",".join(chemsys)})

        if elements:
            query_params.update({"elements": ",".join(elements)})

        if exclude_elements:
            query_params.update({"exclude_elements": ",".join(exclude_elements)})

        return super()._search(
            num_chunks=num_chunks,
            chunk_size=chunk_size,
            all_fields=all_fields,
            fields=fields,
            **query_params,
        )