lcmodel-wrapper 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/PKG-INFO +1 -1
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/_version.py +1 -1
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/control.py +18 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/core.py +12 -3
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/PKG-INFO +1 -1
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/SOURCES.txt +1 -0
- lcmodel_wrapper-0.4.0/tests/test_control.py +56 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/LICENSE +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/LICENSE.lcmodel +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/MANIFEST.in +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/NOTICE +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/README.md +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/__init__.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/basis.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/binaries.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/container.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/convert.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/coord.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper/io.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/dependency_links.txt +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/requires.txt +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/top_level.txt +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/pyproject.toml +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/setup.cfg +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/tests/test_binaries.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/tests/test_convert.py +0 -0
- {lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/tests/test_lcm.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
# Single source of truth for the package version. pyproject.toml reads it at build time,
|
|
2
2
|
# and binaries.py derives the GitHub release / container image tag ("v<version>") from
|
|
3
3
|
# it, so every wheel pairs with the LCModel artifacts built alongside it.
|
|
4
|
-
__version__ = "0.
|
|
4
|
+
__version__ = "0.4.0"
|
|
@@ -90,6 +90,24 @@ def load_control(control_path: str, path2basis: str, ppmlim: Tuple[float, float]
|
|
|
90
90
|
return control
|
|
91
91
|
|
|
92
92
|
|
|
93
|
+
#********************#
|
|
94
|
+
# set parameters #
|
|
95
|
+
#********************#
|
|
96
|
+
def set_params(control: List[str], params: dict) -> List[str]:
|
|
97
|
+
"""Set each of *params* in place, written as LCModel's namelist expects.
|
|
98
|
+
|
|
99
|
+
Strings are quoted unless they already are, and booleans become T or F; anything
|
|
100
|
+
else is written as it is.
|
|
101
|
+
"""
|
|
102
|
+
for key, value in params.items():
|
|
103
|
+
if isinstance(value, bool):
|
|
104
|
+
value = "T" if value else "F"
|
|
105
|
+
elif isinstance(value, str) and not value.startswith("'"):
|
|
106
|
+
value = f"'{value}'"
|
|
107
|
+
set_key(control, key, value)
|
|
108
|
+
return control
|
|
109
|
+
|
|
110
|
+
|
|
93
111
|
#********************************#
|
|
94
112
|
# set a key in a control set #
|
|
95
113
|
#********************************#
|
|
@@ -104,13 +104,19 @@ class PyLCModel:
|
|
|
104
104
|
Seconds to wait for the ".coord" output after LCModel exits. Only covers metadata
|
|
105
105
|
lag on network filesystems; raises "LCModelError" with LCModel's diagnostics when
|
|
106
106
|
the fit produced nothing.
|
|
107
|
+
params : dict, optional
|
|
108
|
+
Further LCModel control parameters by their control-file names, e.g.
|
|
109
|
+
{"nuse1": 2, "chuse1(1)": "NAA", "chuse1(2)": "Cr"}. Applied on top of the
|
|
110
|
+
control however it is made - built, loaded from "control", or rebuilt once the
|
|
111
|
+
data is known - so a setting or two needs no control file of its own.
|
|
107
112
|
"""
|
|
108
113
|
|
|
109
114
|
def __init__(self, path2basis, control=None, multiprocessing=False, ppmlim=(0.5, 4.2),
|
|
110
115
|
conj=True, ignore="default", save_path="", path2exec=None,
|
|
111
116
|
domain="time", sample_points=None, bandwidth=None, central_freq=None,
|
|
112
117
|
allow_download=True, allow_docker=True, allow_build=True,
|
|
113
|
-
convert_basis=False, basis_format=None, timeout=900, io_timeout=10
|
|
118
|
+
convert_basis=False, basis_format=None, timeout=900, io_timeout=10,
|
|
119
|
+
params=None):
|
|
114
120
|
|
|
115
121
|
if convert_basis:
|
|
116
122
|
conv_dwell = (1.0 / bandwidth) if bandwidth else None
|
|
@@ -119,6 +125,7 @@ class PyLCModel:
|
|
|
119
125
|
)
|
|
120
126
|
self.path2basis = path2basis
|
|
121
127
|
self.basis = read_basis(path2basis)
|
|
128
|
+
self.params = dict(params or {})
|
|
122
129
|
|
|
123
130
|
self.multiprocessing = multiprocessing
|
|
124
131
|
self.save_path = save_path
|
|
@@ -156,7 +163,8 @@ class PyLCModel:
|
|
|
156
163
|
self._ignore = control_mod.resolve_ignore(ignore)
|
|
157
164
|
|
|
158
165
|
if control is not None:
|
|
159
|
-
self.control = control_mod.
|
|
166
|
+
self.control = control_mod.set_params(
|
|
167
|
+
control_mod.load_control(control, path2basis, ppmlim, self._ignore), self.params)
|
|
160
168
|
else:
|
|
161
169
|
self.control = self._build_control()
|
|
162
170
|
|
|
@@ -164,10 +172,11 @@ class PyLCModel:
|
|
|
164
172
|
# helpers #
|
|
165
173
|
#*************#
|
|
166
174
|
def _build_control(self):
|
|
167
|
-
|
|
175
|
+
control = control_mod.build_control(
|
|
168
176
|
self.path2basis, self.sample_points, self.bandwidth, self.central_freq,
|
|
169
177
|
ppmlim=self.ppmlim, ignore=self._ignore,
|
|
170
178
|
)
|
|
179
|
+
return control_mod.set_params(control, self.params)
|
|
171
180
|
|
|
172
181
|
def _workdir(self):
|
|
173
182
|
"""Directory for LCModel's input and output files, with a trailing separator.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
# test_control.py #
|
|
3
|
+
####################################################################################################
|
|
4
|
+
# #
|
|
5
|
+
# Purpose: Extra control parameters: written in LCModel's namelist syntax, and kept whichever #
|
|
6
|
+
# way the control is made, including when it is rebuilt once the data is known. #
|
|
7
|
+
# #
|
|
8
|
+
####################################################################################################
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
17
|
+
|
|
18
|
+
from lcmodel_wrapper import PyLCModel, binaries
|
|
19
|
+
from lcmodel_wrapper.control import build_control, set_params
|
|
20
|
+
|
|
21
|
+
_BASIS = (Path(__file__).resolve().parent.parent / "example_data" / "2016_fitting_challenge"
|
|
22
|
+
/ "basisset_LCModel" / "press3T_30ms.BASIS")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
#************#
|
|
26
|
+
# syntax #
|
|
27
|
+
#************#
|
|
28
|
+
def test_params_are_written_as_the_namelist_expects():
|
|
29
|
+
control = set_params(build_control("x.basis", 2048, 4000.0, 123.2),
|
|
30
|
+
{"nuse1": 2, "chuse1(1)": "NAA", "dows": True, "namrel": "'Cr'"})
|
|
31
|
+
|
|
32
|
+
assert "nuse1=2" in control and "chuse1(1)='NAA'" in control
|
|
33
|
+
assert "dows=T" in control and "namrel='Cr'" in control
|
|
34
|
+
assert control[-1] == "$END"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
#*************#
|
|
38
|
+
# rebuilt #
|
|
39
|
+
#*************#
|
|
40
|
+
def _binary():
|
|
41
|
+
try:
|
|
42
|
+
return binaries.resolve_executable(allow_download=False, allow_build=False)
|
|
43
|
+
except Exception: # noqa: BLE001 - any failure means absent
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.skipif(not _BASIS.exists() or _binary() is None,
|
|
48
|
+
reason="needs the challenge basis and a cached LCModel binary")
|
|
49
|
+
def test_params_survive_the_control_being_rebuilt():
|
|
50
|
+
"""The control is rebuilt from the data at fit time; the params must outlive that."""
|
|
51
|
+
engine = PyLCModel(str(_BASIS), params={"chuse1(1)": "NAA"},
|
|
52
|
+
allow_download=False, allow_build=False, allow_docker=False)
|
|
53
|
+
|
|
54
|
+
assert "chuse1(1)='NAA'" in engine.control
|
|
55
|
+
engine.sample_points += 1 # as a different acquisition would
|
|
56
|
+
assert "chuse1(1)='NAA'" in engine._build_control()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lcmodel_wrapper-0.3.2 → lcmodel_wrapper-0.4.0}/lcmodel_wrapper.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|