Skip to content

Commit

Permalink
Merge pull request #264 from nlesc-nano/PA-ARMC
Browse files Browse the repository at this point in the history
BUG: Fix PES-averaged ARMC failing to create multiple `ParamMapping` columns
  • Loading branch information
BvB93 committed Jan 28, 2022
2 parents da02694 + f525d64 commit 8907845
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
9 changes: 9 additions & 0 deletions FOX/armc/param_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ def __call__(self, logger: Optional[Logger] = None,
self.param.loc[idx, param_idx] = value
return idx

def set_n_columns(self, n: int) -> None:
if len(self.param.columns) != 1:
raise ValueError
for i in range(1, n):
self.param[i] = self.param[0]
self.param_old[i] = self.param_old[0]
for j in self.metadata.columns.levels[1]:
self.metadata[i, j] = self.metadata[0, j]

@abstractmethod
def identify_move(self, param_idx: int) -> Tuple[Tup3, float, float]:
"""Identify the to-be moved parameter and the size of the move.
Expand Down
7 changes: 4 additions & 3 deletions FOX/armc/sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def dict_to_armc(input_dict: MainMapping) -> Tuple[MonteCarloABC, RunDict]:
phi = get_phi(dct['phi'])
package, mol_list = get_package(dct['job'], phi.phi)
param, _param, _param_frozen, validation_dict = get_param(dct['param'])
if len(mol_list) > 1:
param.set_n_columns(len(mol_list))
mc, run_kwargs = get_armc(dct['monte_carlo'], package, param, phi, mol_list)

# Handle psf stuff
Expand Down Expand Up @@ -758,11 +760,10 @@ def update_count(param, psf=None, mol=None): # noqa: E302
index = param.metadata.index
prm_count_list = [param.metadata[i, 'count'] for i in param.metadata.columns.levels[0]]
at_sequence = [atoms.split() for *_, atoms in index]
for count in count_iter:
for prm_count, count in zip(prm_count_list, count_iter):
data = get_atom_count(at_sequence, count)
series = pd.Series({k: v for k, v in zip(index, data) if v is not None}, name='unit')
for prm_count in prm_count_list:
prm_count.update(series)
prm_count.update(series)


def _assign_residues(plams_mol: Molecule, res_list: Iterable[Iterable[int]]) -> None:
Expand Down
19 changes: 18 additions & 1 deletion docs/4_monte_carlo_args.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,30 @@ each containg the :attr:`func<pes_validation.block.func>` and, optionally,

.. attribute:: pes_validation.block.kwargs

:Parameter: * **Type** - :class:`dict[str, object] <dict>`
:Parameter: * **Type** - :class:`dict[str, object] <dict>` or :class:`list[dict[str, object]] <list>`
* **Default Value** - ``{}``

A dictionary with keyword arguments for :attr:`func<pes_validation.block.func>`.

The structure of this block is identintical to its counterpart in :attr:`pes.block.kwargs`.

Passing a list of dictionaries allows one the use different kwargs for
different jobs in PES-averaged ARMC or ARMCPT:

.. code-block:: yaml
job:
molecule:
- mol_CdSeO.xyz
- mol_CdSeN.xyz
pes_validation:
rdf:
func: FOX.MultiMolecule.init_rdf
kwargs:
- atom_subset: [Cd, Se, O]
- atom_subset: [Cd, Se, N]
.. _monte_carlo_parameters.job:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_signature(self) -> None:
class TestFromResult:
def test_no_reduce(self, func: FromResult, ref: np.ndarray) -> None:
prop = func.from_result(RESULT)
np.testing.assert_allclose(prop, ref)
np.testing.assert_allclose(prop, ref, rtol=1e-06)

def test_reduce_mean(self, func: FromResult, ref: np.ndarray) -> None:
prop = func.from_result(RESULT, reduce='mean', axis=0)
Expand Down

0 comments on commit 8907845

Please sign in to comment.