Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyscal solid liquid #414

Merged
merged 7 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion pyiron_atomistics/atomistics/structure/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy.sparse import coo_matrix
from scipy.spatial import Voronoi
from pyiron_atomistics.atomistics.structure.pyscal import get_steinhardt_parameter_structure, analyse_cna_adaptive, \
analyse_centro_symmetry, analyse_diamond_structure, analyse_voronoi_volume
analyse_centro_symmetry, analyse_diamond_structure, analyse_voronoi_volume, pyiron_to_pyscal_system, analyse_find_solids
from pyiron_atomistics.atomistics.structure.strain import Strain
from pyiron_base.generic.util import Deprecator
from scipy.spatial import ConvexHull
Expand Down Expand Up @@ -532,6 +532,40 @@ def pyscal_voronoi_volume(self):
""" Calculate the Voronoi volume of atoms """
return analyse_voronoi_volume(atoms=self._structure)

def pyscal_find_solids(self, neighbor_method="cutoff",
cutoff=0, bonds=0.5,
threshold=0.5, avgthreshold=0.6,
cluster=False, q=6, right=True,
return_sys=False,
):
"""
Get the number of solids or the corresponding pyscal system.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I misunderstood the method, I thought or should be of or some such... I promise to read more carefully next time. ;)

Calls necessary pyscal methods as described in https://pyscal.org/en/latest/methods/03_solidliquid.html.

Args:
neighbor_method (str, optional): Method used to get neighborlist. See pyscal documentation. Defaults to "cutoff".
cutoff (int, optional): Adaptive if 0. Defaults to 0.
bonds (float, optional): Number or fraction of bonds to consider atom as solid. Defaults to 0.5.
threshold (float, optional): See pyscal documentation. Defaults to 0.5.
avgthreshold (float, optional): See pyscal documentation. Defaults to 0.6.
cluster (bool, optional): See pyscal documentation. Defaults to False.
q (int, optional): Steinhard parameter to calculate. Defaults to 6.
right (bool, optional): See pyscal documentation. Defaults to True.
return_sys (bool, optional): Whether to return number of solid atoms or pyscal system. Defaults to False.

Returns:
int: number of solids,
pyscal system: pyscal system when return_sys=True
"""
return analyse_find_solids(atoms=self._structure,
neighbor_method=neighbor_method,
cutoff=cutoff, bonds=bonds,
threshold=threshold,
avgthreshold=avgthreshold,
cluster=cluster, q=q,
right=right, return_sys=return_sys,
)

def get_voronoi_vertices(self, epsilon=2.5e-4, distance_threshold=0, width_buffer=10):
"""
Get voronoi vertices of the box.
Expand Down
3 changes: 3 additions & 0 deletions pyiron_atomistics/atomistics/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import warnings
import seekpath
from pyiron_atomistics.atomistics.structure.atom import Atom, ase_to_pyiron as ase_to_pyiron_atom
from pyiron_atomistics.atomistics.structure.pyscal import pyiron_to_pyscal_system
from pyiron_atomistics.atomistics.structure.neighbors import Neighbors, Tree
from pyiron_atomistics.atomistics.structure._visualize import Visualize
from pyiron_atomistics.atomistics.structure.analyse import Analyse
Expand Down Expand Up @@ -2435,6 +2436,8 @@ def to_pymatgen(self):
def to_ovito(self):
return pyiron_to_ovito(self)

def to_pyscal_system(self):
return pyiron_to_pyscal_system(self)

class _CrystalStructure(Atoms):
"""
Expand Down
75 changes: 57 additions & 18 deletions pyiron_atomistics/atomistics/structure/pyscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,10 @@ def get_steinhardt_parameter_structure(atoms, neighbor_method="cutoff", cutoff=0
numpy.ndarray: (number of q's, number of atoms) shaped array of q parameters
numpy.ndarray: If `clustering=True`, an additional per-atom array of cluster ids is also returned
"""
s.publication_add(publication())
sys = pyiron_to_pyscal_system(atoms)
q = (4, 6) if q is None else q
if clustering == False:
n_clusters = None
sys = pc.System()
sys.read_inputfile(
pyiron_atomistics.atomistics.structure.atoms.pyiron_to_ase(atoms),
format='ase'
)

sys.find_neighbors(
method=neighbor_method,
Expand Down Expand Up @@ -90,9 +85,7 @@ def analyse_centro_symmetry(atoms, num_neighbors=12):
Returns:
csm (list) : list of centrosymmetry parameter
"""
s.publication_add(publication())
sys = pc.System()
sys.read_inputfile(atoms, format="ase")
sys = pyiron_to_pyscal_system(atoms)
return np.array(sys.calculate_centrosymmetry(nmax=num_neighbors))


Expand All @@ -113,9 +106,7 @@ def analyse_diamond_structure(atoms, mode="total", ovito_compatibility=False):
Returns:
(depends on `mode`)
"""
s.publication_add(publication())
sys = pc.System()
sys.read_inputfile(atoms, format="ase")
sys = pyiron_to_pyscal_system(atoms)
diamond_dict = sys.identify_diamond()

ovito_identifiers = [
Expand Down Expand Up @@ -186,7 +177,7 @@ def analyse_cna_adaptive(atoms, mode="total", ovito_compatibility=False):
Returns:
(depends on `mode`)
"""
s.publication_add(publication())
sys = pyiron_to_pyscal_system(atoms)
if mode not in ["total", "numeric", "str"]:
raise ValueError("Unsupported mode")

Expand All @@ -199,8 +190,6 @@ def analyse_cna_adaptive(atoms, mode="total", ovito_compatibility=False):
'CommonNeighborAnalysis.counts.ICO'
]

sys = pc.System()
sys.read_inputfile(atoms, format="ase")
cna = sys.calculate_cna()

if mode == "total":
Expand Down Expand Up @@ -234,13 +223,63 @@ def analyse_voronoi_volume(atoms):
Args:
atoms : (pyiron_atomistics.structure.atoms.Atoms): The structure to analyze.
"""
s.publication_add(publication())
sys = pc.System()
sys.read_inputfile(atoms, format="ase")
sys = pyiron_to_pyscal_system(atoms)
sys.find_neighbors(method="voronoi")
atoms = sys.atoms
return np.array([atom.volume for atom in atoms])

def pyiron_to_pyscal_system(atoms):
"""
Converts atoms to ase atoms and than to a pyscal system.
Also adds the pyscal publication.

Args:
atoms (pyiron atoms): Structure to convert.

Returns:
Pyscal system: See the pyscal documentation.
"""
s.publication_add(publication())
sys = pc.System()
sys.read_inputfile(
pyiron_atomistics.atomistics.structure.atoms.pyiron_to_ase(atoms),
format="ase",
)
return sys

def analyse_find_solids(atoms, neighbor_method="cutoff",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the number of atoms that are inside a solid phase? If so it'd cool to also return an index array, that shows which are solid and which are liquid, maybe behind a switch, like the pyscal_adaptive_cna method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only returns the number by default, but when using return_system=True it returns the complete pyscal system object, which allows to get the indices. I thought this is the most simple in the default case and the most flexible approach when using the return_system option.
Alternatively I could change the default to return an array with the indices of all atoms that are identified as solid, so that the len(returned_array) gives the number of solids I guess. But I do not know if the order of the atoms stays the same when converting between pyiron ase and pyscal system, so I am not sure if indices will always be correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I had simply missed that while skimming. Since anything might happen while changing from pyiron to pyscal returning the full system is ok, I suppose.

cutoff=0, bonds=0.5,
threshold=0.5, avgthreshold=0.6,
cluster=False, q=6, right=True,
return_sys=False,
):
"""
Get the number of solids or the corresponding pyscal system.
Calls necessary pyscal methods as described in https://pyscal.org/en/latest/methods/03_solidliquid.html.

Args:
neighbor_method (str, optional): Method used to get neighborlist. See pyscal documentation. Defaults to "cutoff".
cutoff (int, optional): Adaptive if 0. Defaults to 0.
bonds (float, optional): Number or fraction of bonds to consider atom as solid. Defaults to 0.5.
threshold (float, optional): See pyscal documentation. Defaults to 0.5.
avgthreshold (float, optional): See pyscal documentation. Defaults to 0.6.
cluster (bool, optional): See pyscal documentation. Defaults to False.
q (int, optional): Steinhard parameter to calculate. Defaults to 6.
right (bool, optional): See pyscal documentation. Defaults to True.
return_sys (bool, optional): Whether to return number of solid atoms or pyscal system. Defaults to False.

Returns:
int: number of solids,
pyscal system: pyscal system when return_sys=True
"""
sys = pyiron_to_pyscal_system(atoms)
sys.find_neighbors(method=neighbor_method, cutoff=cutoff)
sys.find_solids(bonds=bonds, threshold=threshold, avgthreshold=avgthreshold, q=q, cutoff=cutoff, cluster=cluster, right=right)
if return_sys:
return sys
atoms = sys.atoms
solids = [atom for atom in atoms if atom.solid]
return len(solids)

def publication():
return {
Expand Down