Skip to content

Commit

Permalink
Merge pull request #365 from ISISNeutronMuon/fix-voronoi
Browse files Browse the repository at this point in the history
Fix voronoi
  • Loading branch information
ChiCheng45 authored Mar 18, 2024
2 parents 1f3f028 + 43f6153 commit 06716eb
Show file tree
Hide file tree
Showing 26 changed files with 652 additions and 150 deletions.
16 changes: 2 additions & 14 deletions MDANSE/Src/MDANSE/Extensions/.gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
/distance_histogram.so
/fast_calculation.so
/mic_fast_calc.so
/mt_fast_calc.so
/qhull.so
/sas_fast_calc.so
/sd_fast_calc.so
/distance_histogram.o
/fast_calculation.o
/mic_fast_calc.o
/mt_fast_calc.o
/qhull.o
/sas_fast_calc.o
/sd_fast_calc.o
*.o
*.so
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ def configure(self, value):
self.update(value)

e1 = find_atoms_in_molecule(
trajConfig["instance"].universe, self["molecule"], self["endpoint1"], True
trajConfig["instance"]._chemical_system,
self["molecule"],
self["endpoint1"],
True,
)
e2 = find_atoms_in_molecule(
trajConfig["instance"].universe, self["molecule"], self["endpoint2"], True
trajConfig["instance"]._chemical_system,
self["molecule"],
self["endpoint2"],
True,
)

self["value"] = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HDFInputFileConfigurator(InputFileConfigurator):
This configurator allows to input an HDF file as input file.
"""

_default = "INPUT_FILENAME.h5"
_default = "INPUT_FILENAME.mda"

def __init__(self, name, variables=None, **kwargs):
"""
Expand All @@ -42,6 +42,7 @@ def __init__(self, name, variables=None, **kwargs):
InputFileConfigurator.__init__(self, name, **kwargs)

self._variables = variables if variables is not None else []
self._units = {}

def configure(self, value):
"""
Expand All @@ -67,6 +68,10 @@ def configure(self, value):
for v in self._variables:
if v in self["instance"]:
self[v] = self["instance"][v][:]
try:
self._units[v] = self["instance"][v].attrs["units"]
except:
self._units[v] = "unitless"
else:
self.error_status = (
f"the variable {v} was not found in {value} HDF file"
Expand All @@ -87,7 +92,7 @@ def variables(self):

def get_information(self):
"""
Returns some basic informations about the contents of theHDF file.
Returns some basic informations about the contents of the HDF file.
:return: the informations about the contents of the HDF file.
:rtype: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import tempfile
import time
from typing import Dict, Any

from MDANSE import PLATFORM
from MDANSE.Framework.Configurators.IConfigurator import (
Expand All @@ -24,6 +25,26 @@
)


def parse_dictionary(input: str) -> Dict[str, Any]:
big_line = input.strip("\{\}[] \n")
tokens = big_line.split(",")
result = {}
for entry in tokens:
temp = entry.split(":")
key, value = temp[0], ":".join(temp[1:])
key = key.strip("' ")
value = value.strip(" '")
try:
value = int(value)
except:
try:
value = float(value)
except:
pass
result[key] = value
return result


class McStasOptionsConfigurator(IConfigurator):
"""
This configurator allows to input the McStas options that will be used to run a McStas executable file.
Expand All @@ -50,7 +71,9 @@ def configure(self, value):

options = self._default.copy()

for k, v in list(value.items()):
parsed = parse_dictionary(value)

for k, v in list(parsed.items()):
if k not in options:
continue
options[k] = v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

from MDANSE import PLATFORM
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator
from MDANSE.Framework.Configurators.McStasOptionsConfigurator import parse_dictionary


class McStasParametersConfigurator(IConfigurator):
"""
This configurator allows to input the McStas instrument parameters that will be used to run a McStas executable file.
"""

_mcStasTypes = {"double": float, "int": int, "StringConfigurator": str}
_mcStasTypes = {"double": float, "int": int, "string": str}

_default = {
"beam_wavelength_Angs": 2.0,
Expand Down Expand Up @@ -77,20 +78,27 @@ def configure(self, value):
[exePath, "-h"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)

parameters_bytes = s.communicate()[0]
parameters_string = parameters_bytes.decode(encoding="utf-8")

instrParameters = dict(
[
(v[0], [v[1], v[2]])
for v in re.findall(
"\s*(\w+)\s*\((\w+)\)\s*\[default='(\S+)'\]", s.communicate()[0]
"\s*(\w+)\s*\((\w+)\)\s*\[default='(\S+)'\]", parameters_string
)
if v[0] not in self._exclude
]
)

val = {}
for k, v in list(value.items()):
parsed = parse_dictionary(value)
print(f"Parsed input: {parsed}")
print(f"Received from McStas: {instrParameters}")
for k, v in list(parsed.items()):
if k not in instrParameters:
instrParameters.pop(k)
# instrParameters.pop(k) # how was that supposed to work?
continue
val[k] = self._mcStasTypes[instrParameters[k][0]](v)

self["value"] = ["%s=%s" % (k, v) for k, v in list(val.items())]
Expand Down
8 changes: 6 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Formats/MDAFormat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from MDANSE.Framework.Formats.IFormat import IFormat
from MDANSE.Framework.OutputVariables import IOutputVariable

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from MDANSE.Framework.OutputVariables.IOutputVariable import IOutputVariable
from .HDFFormat import HDFFormat


Expand All @@ -22,7 +26,7 @@ class MDAFormat(IFormat):
def write(
cls,
filename: str,
data: dict[str, IOutputVariable],
data: dict[str, "IOutputVariable"],
header: str = "",
extension: str = extensions[0],
) -> None:
Expand Down
2 changes: 2 additions & 0 deletions MDANSE/Src/MDANSE/Framework/Jobs/CoordinationNumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CoordinationNumber(DistanceHistogram):

label = "Coordination Number"

enabled = True

category = (
"Analysis",
"Structure",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run_step(self, index):
variables = copy.deepcopy(current_configuration.variables)
coords = variables.pop("coordinates")
current_configuration = RealConfiguration(
trajectory.chemical_system, coords, None, **variables
trajectory.chemical_system, coords, **variables
)

trajectory.chemical_system.configuration = current_configuration
Expand Down
Loading

0 comments on commit 06716eb

Please sign in to comment.