Skip to content
New issue

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

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

Already on GitHub? # to your account

Change default VoronoiNN cutoff #1289

Merged
merged 1 commit into from
Sep 26, 2018
Merged
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
32 changes: 22 additions & 10 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class VoronoiNN(NearNeighbors):
(default: 0).
targets (Element or list of Elements): target element(s).
cutoff (float): cutoff radius in Angstrom to look for near-neighbor
atoms. Defaults to 10.0.
atoms. Defaults to 13.0.
allow_pathological (bool): whether to allow infinite vertices in
determination of Voronoi coordination.
weight (string) - Statistic used to weigh neighbors (see the statistics
Expand All @@ -600,7 +600,7 @@ class VoronoiNN(NearNeighbors):
for faster performance
"""

def __init__(self, tol=0, targets=None, cutoff=10.0,
def __init__(self, tol=0, targets=None, cutoff=13.0,
allow_pathological=False, weight='solid_angle',
extra_nn_info=True, compute_adj_neighbors=True):
super(VoronoiNN, self).__init__()
Expand Down Expand Up @@ -645,8 +645,12 @@ def get_voronoi_polyhedra(self, structure, n):
center = structure[n]

cutoff = self.cutoff
max_cutoff = np.linalg.norm(
structure.lattice.lengths_and_angles[0]) + 0.01 # diagonal of cell

# max cutoff is the longest diagonal of the cell + room for noise
corners = [[1, 1, 1], [-1, 1, 1], [1, -1, 1], [1, 1, -1]]
d_corners = [np.linalg.norm(structure.lattice.get_cartesian_coords(c))
for c in corners]
max_cutoff = max(d_corners) + 0.01

while True:
try:
Expand All @@ -657,19 +661,27 @@ def get_voronoi_polyhedra(self, structure, n):

# Run the Voronoi tessellation
qvoronoi_input = [s.coords for s in neighbors]

voro = Voronoi(
qvoronoi_input) # can give seg fault if cutoff is too small

# Extract data about the site in question
cell_info = self._extract_cell_info(
structure, 0, neighbors, targets, voro,
self.compute_adj_neighbors)
break

except RuntimeError:
except RuntimeError as e:
if cutoff >= max_cutoff:
raise RuntimeError("Error in Voronoi neighbor finding; max "
"cutoff exceeded")
if e.args and "vertex" in e.args[0]:
# pass through the error raised by _extract_cell_info
raise e
else:
raise RuntimeError("Error in Voronoi neighbor finding; "
"max cutoff exceeded")
cutoff = min(cutoff * 2, max_cutoff + 0.001)
return cell_info

# Extract data about the site in question
return self._extract_cell_info(structure, 0, neighbors, targets, voro,
self.compute_adj_neighbors)

def get_all_voronoi_polyhedra(self, structure):
"""Get the Voronoi polyhedra for all site in a simulation cell
Expand Down