Skip to content

Commit

Permalink
Change to using the phrase uncertainty_params
Browse files Browse the repository at this point in the history
  • Loading branch information
arm61 committed Nov 5, 2023
1 parent 12bbb16 commit e2dcee6
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 122 deletions.
26 changes: 21 additions & 5 deletions docs/source/vasp_d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"metadata": {},
"outputs": [],
"source": [
"b_params = {'dimension': 'xy'}"
"u_params = {'dimension': 'xy'}"
]
},
{
Expand All @@ -65,7 +65,7 @@
"outputs": [],
"source": [
"xd = Xdatcar('./example_XDATCAR.gz')\n",
"diff = DiffusionAnalyzer.from_Xdatcar(xd, parser_params=p_params, bootstrap_params=b_params)"
"diff = DiffusionAnalyzer.from_Xdatcar(xd, parser_params=p_params, uncertainty_params=b_params)"
]
},
{
Expand Down Expand Up @@ -136,7 +136,7 @@
"metadata": {},
"outputs": [],
"source": [
"diff.diffusion(diff.ngp_max)"
"diff.diffusion(0.4)"
]
},
{
Expand Down Expand Up @@ -334,6 +334,15 @@
" 'progress': False})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loaded_diff.dt[:]"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -342,7 +351,7 @@
"source": [
"plt.plot(loaded_diff.dt, loaded_diff.msd, 'k-')\n",
"for i, ci in enumerate(credible_intervals):\n",
" plt.fill_between(loaded_diff.dt[5:],\n",
" plt.fill_between(loaded_diff.dt[3:],\n",
" *np.percentile(ppd.T, ci, axis=1),\n",
" alpha=alpha[i],\n",
" color='#0173B2',\n",
Expand All @@ -351,11 +360,18 @@
"plt.xlabel('$\\Delta t$/ps')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "intensive",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
12 changes: 6 additions & 6 deletions docs/source/vasp_dj.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"While the `b_params` dictionary describes the details of the bootstrapping process, these are documented in the [diffusion module](./diffusion.html#kinisi.diffusion.MSDBootstrap). Here, we indicate that we only want to investigate diffusion in the *xy*-plane of the system."
"While the `u_params` dictionary describes the details of the uncertainty calculation process, these are documented in the [diffusion module](./diffusion.html#kinisi.diffusion.MSDBootstrap). Here, we indicate that we only want to investigate diffusion in the *xy*-plane of the system."
]
},
{
Expand All @@ -61,7 +61,7 @@
},
"outputs": [],
"source": [
"b_params = {'dimension': 'xyz'}"
"u_params = {'dimension': 'xy'}"
]
},
{
Expand All @@ -73,7 +73,7 @@
"outputs": [],
"source": [
"xd = Xdatcar('./example_XDATCAR.gz')\n",
"diff = JumpDiffusionAnalyzer.from_Xdatcar(xd, parser_params=p_params, bootstrap_params=b_params)"
"diff = JumpDiffusionAnalyzer.from_Xdatcar(xd, parser_params=p_params, uncertainty_params=u_params)"
]
},
{
Expand Down Expand Up @@ -345,9 +345,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:kinisi]",
"display_name": "kinisi",
"language": "python",
"name": "conda-env-kinisi-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -359,7 +359,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
13 changes: 6 additions & 7 deletions kinisi/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ def _from_pymatgen(cls,
return cls(u.delta_t, u.disp_3d, u._n_o, u.volume, **kwargs)
else:
raise ValueError('The dtype specified was not recognised, please consult the kinisi documentation.')

@classmethod
def _from_ase(cls,
trajectory: List[Union['ase.atoms.Atoms',
List['ase.atoms.Atoms']]],
parser_params: dict,
dtype: str = None,
**kwargs):
trajectory: List[Union['ase.atoms.Atoms', List['ase.atoms.Atoms']]],
parser_params: dict,
dtype: str = None,
**kwargs):
"""
Create a :py:class:`Analyzer` object from a list or nested list of
:py:class:`ase.atoms.Atoms` objects.
Expand Down Expand Up @@ -289,7 +288,7 @@ def _stack_trajectories(u: Union[MDAnalysisParser, PymatgenParser]) -> List[np.n
disp[u[0].disp_3d[i].shape[0] * j:u[0].disp_3d[i].shape[0] * (j + 1)] = u[j].disp_3d[i]
joint_disp_3d.append(disp)
return joint_disp_3d

def posterior_predictive(self, posterior_predictive_params: Union[dict, None] = None):
"""
Sample the posterior predictive distribution. The shape of the resulting array will be
Expand Down
62 changes: 30 additions & 32 deletions kinisi/conductivity_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConductivityAnalyzer(Analyzer):
There is one array in the list for each delta_t value. Note: it is necessary to use a list of arrays as
the number of observations is not necessary the same at each data point.
:param volume: The volume of the simulation cell.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.DiffBootstrap` object. See
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.DiffBootstrap` object. See
the appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
Expand Down Expand Up @@ -64,7 +64,7 @@ def from_pymatgen(cls,
List['pymatgen.core.structure.Structure']]],
parser_params: dict,
dtype: str = None,
bootstrap_params: dict = None,
uncertainty_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
"""
Create a :py:class:`ConductivityAnalyzer` object from a list or nested list of
Expand All @@ -78,29 +78,27 @@ def from_pymatgen(cls,
these constitute a series of :py:attr:`consecutive` trajectories or a series of :py:attr:`identical`
starting points with different random seeds, in which case the `dtype` should be either
:py:attr:`consecutive` or :py:attr:`identical`.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
:return: Relevant :py:class:`ConductivityAnalyzer` object.
"""
if bootstrap_params is None:
bootstrap_params = {}
if uncertainty_params is None:
uncertainty_params = {}
cond_anal = super()._from_pymatgen(trajectory, parser_params, dtype=dtype)
cond_anal._diff = diffusion.MSCDBootstrap(cond_anal._delta_t, cond_anal._disp_3d, ionic_charge, cond_anal._n_o,
**bootstrap_params)
**uncertainty_params)
return cond_anal


@classmethod
def from_ase(cls,
trajectory: List[Union['ase.atoms.Atoms',
List['ase.atom.Atoms']]],
parser_params: dict,
dtype: str = None,
bootstrap_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
trajectory: List[Union['ase.atoms.Atoms', List['ase.atom.Atoms']]],
parser_params: dict,
dtype: str = None,
uncertainty_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
"""
Create a :py:class:`ConductivityAnalyzer` object from a list or nested list of
:py:class:`ase.Atoms` objects.
Expand All @@ -113,26 +111,26 @@ def from_ase(cls,
these constitute a series of :py:attr:`consecutive` trajectories or a series of :py:attr:`identical`
starting points with different random seeds, in which case the `dtype` should be either
:py:attr:`consecutive` or :py:attr:`identical`.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
:return: Relevant :py:class:`ConductivityAnalyzer` object.
"""
if bootstrap_params is None:
bootstrap_params = {}
if uncertainty_params is None:
uncertainty_params = {}
cond_anal = super()._from_ase(trajectory, parser_params, dtype=dtype)
cond_anal._diff = diffusion.MSCDBootstrap(cond_anal._delta_t, cond_anal._disp_3d, ionic_charge, cond_anal._n_o,
**bootstrap_params)
**uncertainty_params)
return cond_anal

@classmethod
def from_Xdatcar(cls,
trajectory: Union['pymatgen.io.vasp.outputs.Xdatcar', List['pymatgen.io.vasp.outputs.Xdatcar']],
parser_params: dict,
dtype: str = None,
bootstrap_params: dict = None,
uncertainty_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
"""
Create a :py:class:`ConductivityAnalyzer` object from a single or a list of
Expand All @@ -146,26 +144,26 @@ def from_Xdatcar(cls,
then it is necessary to identify if these constitute a series of :py:attr:`consecutive` trajectories or a
series of :py:attr:`identical` starting points with different random seeds, in which case the `dtype`
should be either :py:attr:`consecutive` or :py:attr:`identical`.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
:return: Relevant :py:class:`ConductivityAnalyzer` object.
"""
if bootstrap_params is None:
bootstrap_params = {}
if uncertainty_params is None:
uncertainty_params = {}
cond_anal = super()._from_Xdatcar(trajectory, parser_params, dtype=dtype)
cond_anal._diff = diffusion.MSCDBootstrap(cond_anal._delta_t, cond_anal._disp_3d, ionic_charge, cond_anal._n_o,
**bootstrap_params)
**uncertainty_params)
return cond_anal

@classmethod
def from_file(cls,
trajectory: Union[str, List[str]],
parser_params: dict,
dtype: str = None,
bootstrap_params: dict = None,
uncertainty_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
"""
Create a :py:class:`ConductivityAnalyzer` object from a single or a list of Xdatcar file(s).
Expand All @@ -177,26 +175,26 @@ def from_file(cls,
list of files is passed, then it is necessary to identify if these constitute a series of
:py:attr:`consecutive` trajectories or a series of :py:attr:`identical` starting points with different
random seeds, in which case the `dtype` should be either :py:attr:`consecutive` or :py:attr:`identical`.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
:return: Relevant :py:class:`ConductivityAnalyzer` object.
"""
if bootstrap_params is None:
bootstrap_params = {}
if uncertainty_params is None:
uncertainty_params = {}
cond_anal = super()._from_file(trajectory, parser_params, dtype=dtype)
cond_anal._diff = diffusion.MSCDBootstrap(cond_anal._delta_t, cond_anal._disp_3d, ionic_charge, cond_anal._n_o,
**bootstrap_params)
**uncertainty_params)
return cond_anal

@classmethod
def from_universe(cls,
trajectory: 'MDAnalysis.core.universe.Universe',
parser_params: dict,
dtype: str = None,
bootstrap_params: dict = None,
uncertainty_params: dict = None,
ionic_charge: Union[np.ndarray, int] = 1):
"""
Create an :py:class:`ConductivityAnalyzer` object from an :py:class:`MDAnalysis.core.universe.Universe` object.
Expand All @@ -209,18 +207,18 @@ def from_universe(cls,
:py:attr:`identical` starting points with different random seeds, in which case the `dtype` should
be :py:attr:`identical`. For a series of consecutive trajectories, please construct the relevant
object using :py:mod:`MDAnalysis`.
:param bootstrap_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
:param uncertainty_params: The parameters for the :py:class:`kinisi.diffusion.MSDBootstrap` object. See the
appropriate documentation for more guidance on this. Optional, default is the default bootstrap parameters.
:param ionic_charge: The charge on the mobile ions, either an array with a value for each ion or a scalar
if all values are the same. Optional, default is :py:attr:`1`.
:return: Relevant :py:class:`ConductivityAnalyzer` object.
"""
if bootstrap_params is None:
bootstrap_params = {}
if uncertainty_params is None:
uncertainty_params = {}
cond_anal = super()._from_universe(trajectory, parser_params, dtype=dtype)
cond_anal._diff = diffusion.MSCDBootstrap(cond_anal._delta_t, cond_anal._disp_3d, ionic_charge, cond_anal._n_o,
**bootstrap_params)
**uncertainty_params)
return cond_anal

def conductivity(self, start_dt: float, temperature: float, conductivity_params: Union[dict, None] = None):
Expand Down
Loading

0 comments on commit e2dcee6

Please sign in to comment.