Giter Site home page Giter Site logo

materialsvirtuallab / pymatgen-analysis-diffusion Goto Github PK

View Code? Open in Web Editor NEW
84.0 84.0 53.0 23.28 MB

This add-on to pymatgen provides tools for analyzing diffusion in materials.

Home Page: https://guide.materialsvirtuallab.org/pymatgen-diffusion/

License: BSD 3-Clause "New" or "Revised" License

Python 95.54% Makefile 1.72% HTML 0.83% CSS 0.35% Batchfile 1.56%

pymatgen-analysis-diffusion's People

Contributors

acrutt avatar bjmorgan avatar chc273 avatar dependabot-preview[bot] avatar dependabot[bot] avatar esoteric-ephemera avatar hanmeitang avatar hmlli avatar jacksund avatar janosh avatar jmmshn avatar kim-jiyoon avatar matk86 avatar pre-commit-ci[bot] avatar shyuep avatar zhuoying avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymatgen-analysis-diffusion's Issues

[Bug]: analyzer.get_msd_plot failed

Email (Optional)

[email protected]

Version

v2023.8.15

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

The function "get_msd_plot()" is incompatible with the function "pretty_plot" in pymatgen

Code snippet

analyzer.get_msd_plot()

Log output

TypeError                                 Traceback (most recent call last)
Cell In[10], line 1
----> 1 analyzer.get_msd_plot(plt=None)

File ~/soft/anaconda3/envs/pymatgen/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:561, in DiffusionAnalyzer.get_msd_plot(self, plt, mode)
    548 """
    549 Get the plot of the smoothed msd vs time graph. Useful for
    550 checking convergence. This can be written to an image file.
   (...)
    557         time will be plotted.
    558 """
    559 from pymatgen.util.plotting import pretty_plot
--> 561 plt = pretty_plot(12, 8, plt=plt)
    562 if np.max(self.dt) > 100000:
    563     plot_dt = self.dt / 1000

TypeError: pretty_plot() got an unexpected keyword argument 'plt'

Code of Conduct

  • I agree to follow this project's Code of Conduct

Find the low-energy sites from probability density function

In the current implementation of ProbabilityDensityAnalysis class, it does not output the low-energy sites along the diffusion pathways. This piece of information is useful in some diffusion analyses (e.g. effects of local environment on the ionic migration).

[Bug]: Website Access Issue: Materials Virtual Lab pymatgen-diffusion Guide

Email (Optional)

[email protected]

Version

v2023.1.1

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I'm experiencing an issue accessing the Materials Virtual Lab guide for pymatgen-diffusion at the following URL: https://guide.materialsvirtuallab.org/pymatgen-diffusion/. The website appears to be down or inaccessible.

Code snippet

1. Navigate to [https://guide.materialsvirtuallab.org/pymatgen-diffusion/](https://guide.materialsvirtuallab.org/pymatgen-diffusion/).
2. Observe the inability to access the site or receive an error message.

Log output

404 File not found
The site configured at this address does not contain the requested file.
If this is your site, make sure that the filename case matches the URL as well as any file permissions.

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Bug]: van_hove analysis 3d plot function doesnt work!

Email (Optional)

[email protected]

Version

v2024.6.25.1

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

@shyuep similar problems persist in this one too. 1d plotting works fine tho!

Code snippet

for i, analyzer in enumerate(diff_analyzer):
    try:
        print(f"Starting Van Hove Analysis for analyzer {i} at {temperatures[i]}K")

        van_hove = VanHoveAnalysis(
            analyzer,
            avg_nsteps=avg_nsteps,
            ngrid=ngrid,
            rmax=rmax,
            step_skip=step_skip,
            sigma=sigma,
            cell_range=cell_range,
            species=diffusing_species,
            reference_species=reference_species,
            indices=indices
        )

        # Save 3d plot
        van_hove_3d_plot = van_hove.get_3d_plot(mode='distinct')
        van_hove_3d_plot_filename = os.path.join(output_dir, f'van_hove_3d_plot_{i}.png')
        plt.savefig(van_hove_3d_plot_filename)
        plt.close()  # Close the figure to free memory
        print(f"3D plot saved for analyzer {i} at {temperatures[i]}K to {van_hove_3d_plot_filename}")

Log output

Starting Van Hove Analysis for analyzer 0 at 800K
Unexpected error for analyzer 0 at 800K: VanHoveAnalysis.get_3d_plot() got an unexpected keyword argument 'ax'
Starting Van Hove Analysis for analyzer 1 at 1000K
Unexpected error for analyzer 1 at 1000K: VanHoveAnalysis.get_3d_plot() got an unexpected keyword argument 'ax'
Starting Van Hove Analysis for analyzer 2 at 1200K
Unexpected error for analyzer 2 at 1200K: VanHoveAnalysis.get_3d_plot() got an unexpected keyword argument 'ax'
Starting Van Hove Analysis for analyzer 3 at 1400K
Unexpected error for analyzer 3 at 1400K: VanHoveAnalysis.get_3d_plot() got an unexpected keyword argument 'ax'
Starting Van Hove Analysis for analyzer 4 at 1600K
Unexpected error for analyzer 4 at 1600K: VanHoveAnalysis.get_3d_plot() got an unexpected keyword argument 'ax'

Code of Conduct

  • I agree to follow this project's Code of Conduct

How to obtain the .npy file or .json file

Dear Developers,

Thanks for your work, i'm so interested in the the probability_analysis.ipynb. I want to ask a simple question that how could we get the .npy file on our work for generating the .vasp file .By vasp or some other code?could you tell me some details about it?

Thanks for your help in advance,
Regards,
Joey

Enhancement: Allow RadialDistributionFunction to be defined by atom indices

At present the RadialDistributionFunction class is initialised using species and reference_species arguments, to select the atoms used in calculating the RDF. The species labels are used to generate index lists inside the __init__ method: e.g.

indices = [j for j, site in enumerate(structures[0])
                   if site.specie.symbol in species]

This would be more flexible if atoms could be selected directly by index. e.g.

RadialDistributionFunction(spec_indices=[0, 1, 2, 3], ref_spec_indices=[4, 5, 6, 7])

as it would allow you to calculate RDFs for a subset of a particular species (e.g. Li only at specific sites in the lattice).

To allow this and selecting by species labels, I can think of two possible approaches:

  1. Add new optional arguments to the current __init__ method, along with logic to allow defined indices to supersede the default species arguments.
    This has the advantage of not changing the API for RDFs generated using species labels, at the cost of making the API and code more complex.

  2. Change the __init__ method to only accept selection by indices. Selection by species label is moved to a new class method e.g. RadialDistributionFunction.from_species_labels('Li') which contains the code to identify the correct indices, and then calls the class __init__() method. I think this keeps the code logic cleaner, but breaks backwards compatibility with the current API.

[Bug]: get_arrhenius_plot() failed

Email (Optional)

No response

Version

v2023.8.15

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I encountered a TypeError when trying to use the get_arrhenius_plot function from the pymatgen.analysis.diffusion.analyzer module.

Code snippet

https://github.com/materialsvirtuallab/Data-driven-First-Principles-Methods-for-the-Study-and-Design-of-Alkali-Superionic-Conductors/blob/master/notebooks/3%20-%20Diffusivity%20and%20Ionic%20Conductivity.ipynb

Log output

File "/home/lws/Desktop/SSE/analysis.py", line 22, in <module>
    get_arrhenius_plot(temperatures, diffusivities).savefig("arrhenius_plot.png")
File "/home/lws/anaconda3/envs/deepmd/lib/python3.10/site-packages/pymatgen/analysis/diffusion/analyzer.py", line 1099, in get_arrhenius_plot
    ax = plt.axes()
TypeError: 'Axes' object is not callable

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Bug]: msd, arrhenius and van hove plotting functions are not working again after v2024.6.24 release!

Email (Optional)

[email protected]

Version

v2024.6.24

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I reinstalled pymatgen and pymatgen-diffusion-analysis today but still cannot use plotting functions.

Code snippet

analyzer.get_msd_plot(msd_plot_filename)

Log output

Traceback (most recent call last):
  File "/gpfs/fs0/scratch/o/ovoznyy/orhan/conductivity_pymatgen/conductivity.py", line 123, in <module>
    analyzer.get_msd_plot(msd_plot_filename)
  File "/gpfs/fs1/home/o/ovoznyy/orhan/general/lib/python3.12/site-packages/pymatgen/analysis/diffusion/analyzer.py", line 552, in get_msd_plot
    plt.tight_layout()
    ^^^^^^^^^^^^^^^^
AttributeError: 'Axes' object has no attribute 'tight_layout'. Did you mean: '_in_layout'?

Code of Conduct

  • I agree to follow this project's Code of Conduct

User StructureGraph for DistinctPathFinder

I'm trying to add the PR that was previously intended for pymatgen.
#materialsproject/pymatgen#1435

My understanding of the current implementation of DistinctPathFinder is that it only looks for distinct paths and does not keep track of all paths.
My usage scenario requires the full list of hops (I'm planning on analyzing full migrations pathways using either charge density of IDPP). This will require some redesign of the class.
If there are no objections, I would like to rewrite the DistinctPathFinder with the StructureGraph to keep track of all the symmetry equivalent hops. I think I can keep the output as a list of MigrationPaths so it won't affect the rest of the codebase very much.

However, doing this means that we will have to compare any two hops to check if they are equivalent. The only way I can see for doing this is by adding two dummy atoms at the endpoints for each hop and performing structure matching.
So I will have to replace how the set of symmetrically inequivalent hops are generated.

This is going to take some effort and I just wanted to make sure the devs agree with my approach before I start coding this up. And make sure doing this will not disrupt other ongoing efforts.

Thanks in advance.

[Bug]: ValueError: zero-size array to reduction operation maximum which has no identity

Email (Optional)

[email protected]

Version

2024.3.1

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I am attempting to plot the van hove correlation for bulk Na metal:

`analyzer = collections.OrderedDict()

for temp, xdatcar_path in temp_path.items():
if temp == 300:
ionicstep_start = 10764
elif temp == 600:
ionicstep_start = 4943

st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
print(len(st))
analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)`

It give me below error:

10000

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 16
    14 st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
    15 print(len(st))
---> 16 analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:703, in DiffusionAnalyzer.from_structures(cls, structures, specie, temperature, time_step, step_skip, initial_disp, initial_structure, **kwargs)
   700 if initial_disp is not None:
   701     disp += initial_disp[:, None, :]
--> 703 return cls(
   704     structure,
   705     disp,
   706     specie,
   707     temperature,
   708     time_step,
   709     step_skip=step_skip,
   710     lattices=l,
   711     **kwargs,
   712 )

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:411, in DiffusionAnalyzer.__init__(self, structure, displacements, specie, temperature, time_step, step_skip, smoothed, min_obs, avg_nsteps, lattices, c_ranges, c_range_include_edge, structures)
   409 self.corrected_displacements = dc
   410 self.max_ion_displacements = np.max(np.sum(dc**2, axis=-1) ** 0.5, axis=1)
--> 411 self.max_framework_displacement = np.max(
   412     self.max_ion_displacements[framework_indices]
   413 )
   414 self.msd = msd
   415 self.mscd = mscd

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:2810, in max(a, axis, out, keepdims, initial, where)
  2692 @array_function_dispatch(_max_dispatcher)
  2693 @set_module('numpy')
  2694 def max(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
  2695          where=np._NoValue):
  2696     """
  2697     Return the maximum of an array or maximum along an axis.
  2698 
  (...)
  2808     5
  2809     """
-> 2810     return _wrapreduction(a, np.maximum, 'max', axis, None, out,
  2811                           keepdims=keepdims, initial=initial, where=where)

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
    85         else:
    86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation maximum which has no identity
```


I am unable to understand that the XDATCAR file is not empty then why it is unable to read? Kindly @shyuep 
Thanks in advance!

### Code snippet

```python
st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
print(len(st))
analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)`
```


### Log output

```shell
10000

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 16
   14 st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
   15 print(len(st))
---> 16 analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:703, in DiffusionAnalyzer.from_structures(cls, structures, specie, temperature, time_step, step_skip, initial_disp, initial_structure, **kwargs)
  700 if initial_disp is not None:
  701     disp += initial_disp[:, None, :]
--> 703 return cls(
  704     structure,
  705     disp,
  706     specie,
  707     temperature,
  708     time_step,
  709     step_skip=step_skip,
  710     lattices=l,
  711     **kwargs,
  712 )

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:411, in DiffusionAnalyzer.__init__(self, structure, displacements, specie, temperature, time_step, step_skip, smoothed, min_obs, avg_nsteps, lattices, c_ranges, c_range_include_edge, structures)
  409 self.corrected_displacements = dc
  410 self.max_ion_displacements = np.max(np.sum(dc**2, axis=-1) ** 0.5, axis=1)
--> 411 self.max_framework_displacement = np.max(
  412     self.max_ion_displacements[framework_indices]
  413 )
  414 self.msd = msd
  415 self.mscd = mscd

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:2810, in max(a, axis, out, keepdims, initial, where)
 2692 @array_function_dispatch(_max_dispatcher)
 2693 @set_module('numpy')
 2694 def max(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
 2695          where=np._NoValue):
 2696     """
 2697     Return the maximum of an array or maximum along an axis.
 2698 
 (...)
 2808     5
 2809     """
-> 2810     return _wrapreduction(a, np.maximum, 'max', axis, None, out,
 2811                           keepdims=keepdims, initial=initial, where=where)

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
   85         else:
   86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation maximum which has no identity



I am unable to understand when the XDATCAR file is not empty then why it is unable to read? Kindly @shyuep 
Thanks in advance!
```


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

add checking percolating function in neb/pathfinder

For some complicated alkali conductors, the default 5 Angstrom max_path_length will lead to quite many paths and may be more than needed. If we reduce the path length cutoff and can still form the percolating pathways, it would help to either save efforts in unnecessary NEB calculations or quick estimate if a material is a 3D conductor before doing any calculations.

van Hove plots should have other representation options.

Right now, the van Hove plots only support one type of visualization - the spectrum like plot.

I would like options to have this plotted as a 3D surface, or a series of stacked plots (e.g., how people usually plot it in the literature).

Order of atoms in generated path by IDPP solver

Dear Developers,

Thank you for your interesting work on pymatgen-diffusion.

In my testing, I use the following script to generate an initial path of NEB:

the_solver = IDPPSolver.from_endpoints(endpoints=[init_struct, final_struct], nimages=nimages,
sort_tol=sort_tol)
new_path = the_solver.run(maxiter=5000, tol=1e-5, gtol=1e-3, species=species)

This functionality is very convenient for me, however, it is found that the order of atoms in the generated path can be different from those in the given end points (initial_struct, final_struct). For example, the order in O, H will be changed into H, O using the IDPP solver. Since we need to fix some substrate layers in some NEB calculations and these "fix" flags have already been set for the initial/final_struct, it is desired that the generated path can use the same atomic order as given in the initial/final_struct.

Can I easily achieve this by some minor revisions of scripts? Thank you.

Order of atoms in ProbabilityDensityAnalysis.to_chgcar (in pathway.py)

Outputting PDA data in chgcar format can give atoms in the wrong order. This function uses the self.structure.symbol_set to extract the element symbols, but these are stored in alphabetical order, which is not necessarily the order of the atom coordinate data (e.g., as read in from an XDATCAR file) or PDA data, resulting in element symbols and PDA data possibly becoming out of sync.

One way to fix this is to use the same method as in pymatgen.core.trajectory to extract the element symbols in correct order, using itertools functionality.

[Bug]: v2024.6.25 pypi installation doesn't install analyzer.py and init

Email (Optional)

[email protected]

Version

v2024.6.25

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

@shyuep could you please check pypi installer. I downloaded these two files from repo manually and try to run some calcualtions now..

Code snippet

from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer, get_extrapolated_conductivity, \
    get_extrapolated_diffusivity, get_conversion_factor, fit_arrhenius, get_arrhenius_plot

Log output

Traceback (most recent call last):
  File "/gpfs/fs0/scratch/o/ovoznyy/orhan/conductivity_pymatgen/conductivity.py", line 3, in <module>
    from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer, get_extrapolated_conductivity, \
ModuleNotFoundError: No module named 'pymatgen.analysis.diffusion.analyzer'

Code of Conduct

  • I agree to follow this project's Code of Conduct

NEB vacancy supercell generation returns incorrect structure

When you run migrationhop.get_sc_structures(vac_mode=True) the vacancy-based structure is not returned. Instead we just receive an empty host lattice with no diffusing atoms.

As an example, the following code can reproduce the error:

# Load our structure. Note that YbOF is mp-7028
from pymatgen.core.structure import Structure
structure = Structure.from_file("ybof.cif")

# grab the first (and only) pathway found by DistinctPathFinder as an example
from pymatgen.analysis.diffusion.neb.pathfinder import DistinctPathFinder
pathfinder = DistinctPathFinder(structure, migrating_specie="F")
pathway = pathfinder.get_paths()[0] 

# now generate the corresponding supercells for this pathway
structure_start, structure_end, base_supercell = pathway.get_sc_structures(vac_mode=True)

# Let's look at the output and confirm the error.
# Here we expect to see Yb48O48F47 but instead see Yb48O48, which indicates
# we are only getting the host lattice back -- and are missing the diffusing specie
structure_start.composition
structure_end.composition

I have made a fix for this bug and will make a pull request for this shortly.

Finite rounding in endpoint structure creation

Would it be possible to increase the tolerance when deleting atoms for start/end structures?

if not vac_mode or (isite.distance(site) <= 1e-8):

I have a database setup where I'm initializing MigrationHop objects from past data -- so this tolerance is too strict compared to what I'm storing metadata at. When I switch the tolerance from 1e-8 to 1e-5 everything works though. I don't think anyone would need a tolerance lower than a 1e-3 (unless someone is using a physically unreasonable structure). Would it be okay if I opened a pull request for this?

ProbabilityDensityAnalysis results in strange chargcar

Hello,
I get a strange result from ProbabilityDensityAnalysis. Li and transition metal layers are not arranged like POSCAR/CONTCAR. Here is the code I use:
file = ["tem-1000/out_vasprun.xml"]
analyzer = DiffusionAnalyzer.from_files(file, specie="Li", smoothed=False)
structure = analyzer.structure
trajectories = [s.frac_coords for s in analyzer.get_drift_corrected_structures()]
pda = ProbabilityDensityAnalysis(structure, trajectories, species="Li")
pda.to_chgcar("CHGCAR.vasp")
I attach vasprun file below. Hope that someone help me to check.

Screenshot 0004-05-19 at 0 24 26

[AIMD.zip](https://github.com/materialsvirtuallab/pymatgen-analysis-diffusion/files/8717660/AIMD.zip)

how to obtain the .npy and .json file

Dear Developers,
Thanks for your contribution for the pymatgen, I am interested in the probability_analysis.ipynb,I thought it is fantacy. But i don't know how to generate the .npy or the .json file of our own work. By vasp or some other code ?.Could you give me some advice?

Thanks for your help in advance,
Regards,
Joey

DiffusionAnalyzer will fail if there is no framework ions

framework_indices = []
for i, site in enumerate(structure):
if site.specie.symbol == specie:
indices.append(i)
else:
framework_indices.append(i)
if self.disp.shape[1] < 2:
self.diffusivity = 0.0
self.conductivity = 0.0
self.diffusivity_components = np.array([0.0, 0.0, 0.0])
self.conductivity_components = np.array([0.0, 0.0, 0.0])
self.max_framework_displacement = 0
else:
framework_disp = self.disp[framework_indices]
drift = np.average(framework_disp, axis=0)[None, :, :]

DiffusionAnalyzer will fail if there is no framework ions (namely if all ions are mobile)

Basically if framework_indices is an empty list. The first dimension of framework_disp would be 0. Then drift would be a matrix filled with NAN, which leads to failure in the downstream.

This should a minor bug that is easy to fix.

[Bug]: msd, arrhenius and van hove plotting functions are not working!

Email (Optional)

No response

Version

latest

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I want to plot arrhenius, msd and van hove plots but all of them return similar error as you can see below. I just downloaded the last commit by @shyuep but nothing changed. Could you please fix the plotting issues in genereal?

Thank you in advance!

Code snippet

analyzer.get_msd_plot(msd_plot_filename)

Log output

Traceback (most recent call last):
  File "/gpfs/fs0/scratch/o/ovoznyy/orhan/conductivity_pymatgen/conductivity.py", line 123, in <module>
    analyzer.get_msd_plot(msd_plot_filename)
  File "/gpfs/fs1/home/o/ovoznyy/orhan/general/lib/python3.12/site-packages/pymatgen/analysis/diffusion/analyzer.py", line 547, in get_msd_plot
    plt.xlabel(f"Timestep ({unit})")
    ^^^^^^^^^^
AttributeError: 'Axes' object has no attribute 'xlabel'. Did you mean: '_label'?

Code of Conduct

  • I agree to follow this project's Code of Conduct

vasprun.xml generated with ML-MD can't be read

"get_structure" can not properly read machine learning steps in a vasprun.xml file. Any plans to fix the issue or is there a work around (e.g. create a json file containing all the steps)?

Error with get_arrhenius_plot

I am trying an example and plot with get_arrhenius_plot function. No error, but figure does not show information.
temperatures = [600, 800, 1000, 1200]
analyzers = collections.OrderedDict()
for temp in temperatures:
with open("aimd_data/%d.json" % temp) as f:
d = json.load(f)
analyzers[temp] = DiffusionAnalyzer.from_dict(d)
diffusivities = [d.diffusivity for d in analyzers.values()]
#print(temperatures, diffusivities)
plt = get_arrhenius_plot(temperatures, diffusivities)
Screenshot 0004-03-25 at 0 41 01

[Bug]: pretty_plot() gives error due to the breaking change of pymatgen

Email (Optional)

No response

Version

v2023.8.15

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

Due to the breaking change of pymatgen (Breaking: Have plot methods return plt.Axes object, not matplotlib module), the following error comes out in the current version.

pymatgen\analysis\diffusion\analyzer.py", line 560, in get_msd_plot
plt = pretty_plot(12, 8, plt=plt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: pretty_plot() got an unexpected keyword argument 'plt'

Code snippet

No response

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Issue with MSD

Hi, I think the MSD calculation is incorrect. I obtained the smearing, and spiky MSD for the smooth option = False. Because we need to find the fitting slope from MSD(t) line, it is hard to find the best fitting time lag from the spiky MSD. �Maybe a function log(MSD) vs log(t) should be introduced to find the ballistic or diffusive regime, which can not see from a spiky MSD. The user should have an option to choose a suitable time for estimating slop, and diffusivity because the tail of MSD is often removed.
Note: It is surprising that I got the different MSD lines from the same MD output files using the same MSD equation. (compared with MSD obtained from VASPKIT, or Yfei Mo code)
Screenshot 0004-08-07 at 19 24 37

Inaccuracy in RDF calculation over several structures

Dear Developers,

I have used RadialDistributionFunction class in vanhove module of this package and found one ambiguity. Input data are 5 structures with same composition.

While passing single structure, each of them have the first RDF peak at around 2 Angstrom but when I pass all the five structures, the resulting RDF (single plot) shows a peak at 2 Angstrom along with another peak below 2 Angstrom, which to me seems ambiguous. Will you please have a look at it and let me know.

Feel free to ask me if you need the input files for testing.

Thanks for your help in advance,
Regards,
Vishank

Possible bug in RadialDistributionFunction

Hi, I would like to report a possible bug in:

When indx is equal to len(interval) - 1, then IndexError will be raised when we try to get indx + 1 of interval in line 115.

ff = 4.0 / 3.0 * np.pi * (interval[indx + 1] ** 3 - interval[indx] ** 3)

A possible fix would be to change line 111 to: if indx >= len(interval) - 1

Thanks for looking into this!

DistinctPathFinder mislead by __eq__ with long pathway cutoffs

Hi all,

I just wanted to point out a logical bug in the MigrationPath._eq_ function. When we look at extremely long pathways, there are cases where the isite, msite, and esite are all equivalent, but the paths are not. Yes, the longer path is likely unreasonable, but it can mask the pathway of interest. Here's an example using mp-22526 (LiCoO2):

from pymatgen import MPRester
mpr = MPRester(MY_API_KEY)
structure = mpr.get_structure_by_material_id("mp-22526") # LiCoO2

from pymatgen_diffusion.neb.pathfinder import DistinctPathFinder
dpf = DistinctPathFinder(
    structure = structure,
    migrating_specie = 'Li',
    max_path_length = 5, 
    symprec = 0.1,
    perc_mode = None,
    )

paths = dpf.get_paths() # I print out some results of this below

Here, paths will identify the following:

[Path of 4.9240 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [1.000, -2.000, 1.000] (ind: 0, Wyckoff: 1a),
Path of 4.9927 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, 0.000] (ind: 0, Wyckoff: 1a)]

Likewise, if we run the same code with max_path_length = 10 (this a beyond-reasonable cutoff, but I'm just using it to help illustrate the bug) we will obtain the following paths:

[Path of 9.4649 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [3.000, -2.000, -2.000] (ind: 0, Wyckoff: 1a),
Path of 9.5722 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, -1.000] (ind: 0, Wyckoff: 1a),
Path of 9.8826 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [3.000, -1.000, -3.000] (ind: 0, Wyckoff: 1a)]

This is clearly in error as the original pathways identified at 5Ang are not even seen anymore. I've already gone ahead and implemented the fix and tested it -- you simply add the following lines to pymatgen_diffusion.neb.pathfinder at line 330:

# Check that lengths are within 0.0001 Angstroms
if (self.length - other.length) > 1e-4:
     return False

https://github.com/materialsvirtuallab/pymatgen-diffusion/blob/16796454f9c548fb67e57977e7c4c6460355c764/pymatgen_diffusion/neb/pathfinder.py#L330

I choose to hardcode a tolerance of 1e-4 rather than a straight comparison (self.length != other.length) because the lengths often give differences of <1e-6 Angstroms in cases that should be identical. I think it would be fix to loosen this tolerance as well -- even if the path comparison passes on this check, it will continue to symmetrical comparison of sites as it currently does. While this adds an extra check to _eq_, it actually improves the speed of the function! This is because the distance comparison is cheaper than symmetry comparison, which is done as the last step. After the fix, we get the following outputs for the same code used above:

# After Fix;  cutoff = 5Ang
# [Path of 2.8429 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, 1.000] (ind: 0, Wyckoff: 1a),
#  Path of 4.9240 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [1.000, -2.000, 1.000] (ind: 0, Wyckoff: 1a),
#  Path of 4.9927 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, 0.000] (ind: 0, Wyckoff: 1a)]

# After Fix; cutoff = 10Ang
# [Path of 2.8429 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, 1.000] (ind: 0, Wyckoff: 1a),
#  Path of 4.9240 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [1.000, -2.000, 1.000] (ind: 0, Wyckoff: 1a),
#  Path of 4.9927 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, 0.000] (ind: 0, Wyckoff: 1a),
#  Path of 5.7454 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [1.000, -1.000, -1.000] (ind: 0, Wyckoff: 1a),
#  Path of 6.4103 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [1.000, 0.000, -2.000] (ind: 0, Wyckoff: 1a),
#  Path of 7.5216 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [2.000, -3.000, 1.000] (ind: 0, Wyckoff: 1a),
#  Path of 7.5667 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [2.000, -1.000, -2.000] (ind: 0, Wyckoff: 1a),
#  Path of 8.5685 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [2.000, 0.000, -3.000] (ind: 0, Wyckoff: 1a),
#  Path of 9.4649 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [3.000, -2.000, -2.000] (ind: 0, Wyckoff: 1a),
#  Path of 9.5722 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [0.000, -1.000, -1.000] (ind: 0, Wyckoff: 1a),
#  Path of 9.8826 A from Li [0.000, 0.000, 0.000] (ind: 0, Wyckoff: 1a) to Li [3.000, -1.000, -3.000] (ind: 0, Wyckoff: 1a)]

Let me know if you think there's a mistake in my breakdown. Otherwise, if you could add these two lines and release a new version, it would be greatly appreciated! Thanks in advance.

-Jack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.