Skip to content

Commit

Permalink
2.1.0 (#24)
Browse files Browse the repository at this point in the history
* Improved matching (#20)

* Added new atom matching function.

* Added performance tests.

* Update.

* Fixed formatting.

* Updated tests.

* Added performance scripts.

* Updated performance script.

* Updated performance test.

* Replaced test.

* Updated graph search.

* Fixed linting.

* Fixed linting.

* Fixed gitignore.

* Cleanup.

* Updated numpy dependency restriction.

* Started simplifying API.

* Distance calc optimization (#21)

* Trying to disable chemical similarity check.

* updated workflow.

* Fixed formatting.

* Fixed class instantiation.

* Simplified LinkedUnitCollection.

* Fixed formatting.

* Disabled test.

* Simplified LinkedUnitCollection.

* Trying to undo.

* Update.

* Fixed missing default.

* Updated actions.

* Cleaned up old implementations.

* Updated benchmarks.

* Fixed formatting.

* Added branch to tests.

* Optimization (#23)

* Removed unnecesary calculation of finite displacements.

* Removed storing of displacements in matching.

* Removed unnecessary distance calculation with numpy.

* Added guard against invalid cell shape.

* Added guard agains invalid cell

* Fixed formatting.

* Added exception check on cluster cleanup.

* Updated docstring.

* Improved tests.

* Enabled other tests.

* Cleaned up tests.

* Completely removed chemical similarity check.
  • Loading branch information
lauri-codes authored Jul 30, 2024
1 parent 1249e53 commit 16b0b7b
Show file tree
Hide file tree
Showing 17 changed files with 762 additions and 1,510 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: test

on:
push:
branches: [ "main", "v2.0.0"]
branches: [ "main", "2.1.0", "optimization"]
pull_request:
branches: [ "main"]

Expand All @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,11 @@ cython_debug/
#.idea/

# VSCode
.vscode/*
.vscode/*

# Coverage report
coverage
tests/.coverage

# performance results
tests/performance/results
24 changes: 3 additions & 21 deletions matid/classification/classifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,9 @@ def basis_indices(self):

@property
def outliers(self):
return self.region.get_outliers()

@property
def interstitials(self):
return self.region.get_interstitials()

@property
def adsorbates(self):
return self.region.get_adsorbates()

@property
def substitutions(self):
return self.region.get_substitutions()

@property
def vacancies(self):
return self.region.get_vacancies()

@property
def unknowns(self):
return self.region.get_unknowns()
all = set(list(range(len(self.atoms))))
region = self.region.get_basis_indices()
return list(all - region)

@property
def prototype_cell(self):
Expand Down
14 changes: 2 additions & 12 deletions matid/classification/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,18 @@ class that represents a classification.
n_region_conn = np.sum(region_conn)
region_is_periodic = n_region_conn == 2

# This might be unnecessary because the connectivity of the
# unit cell is already checked.
clusters = best_region.get_clusters()
basis_indices = set(list(best_region.get_basis_indices()))
split = True
for cluster in clusters:
if basis_indices.issubset(cluster):
split = False

# Check that the found region covers enough of the entire
# system. If not, then the region alone cannot be used to
# classify the entire structure. This happens e.g. when one
# 2D sheet is found from a 2D heterostructure, or a local
# pattern is found inside a structure.
basis_indices = set(list(best_region.get_basis_indices()))
n_atoms = len(system)
n_basis_atoms = len(basis_indices)
coverage = n_basis_atoms / n_atoms
covered = coverage >= self.min_coverage

if not split and covered and region_is_periodic:
if covered and region_is_periodic:
if best_region.is_2d:
classification = Material2D(input_system, best_region)
else:
Expand Down Expand Up @@ -329,14 +321,12 @@ def cross_validate_region(
cell_size_tol=self.cell_size_tol,
max_2d_cell_height=self.max_2d_cell_height,
max_2d_single_cell_size=self.max_2d_single_cell_size,
chem_similarity_threshold=self.chem_similarity_threshold,
)
region = periodicfinder.get_region(
system,
index,
size,
tol,
self.abs_delaunay_threshold,
self.bond_threshold,
distances=distances,
)
Expand Down
22 changes: 13 additions & 9 deletions matid/clustering/sbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def get_clusters(
distances = matid.geometry.get_distances(system_copy, radii)

# Iteratively search for new clusters until whole system is covered
periodic_finder = PeriodicFinder(
angle_tol=angle_tol, chem_similarity_threshold=0
)
periodic_finder = PeriodicFinder(angle_tol=angle_tol)
indices = set(list(range(len(system_copy))))
clusters = []
while len(indices) != 0:
Expand Down Expand Up @@ -325,12 +323,18 @@ def _clean_clusters(self, clusters, bond_threshold):
Returns:
List of Clusters where any outlier atoms have been removed.
"""
clusters_cleaned = []
for cluster in clusters:
dbscan_clusters = matid.geometry.get_clusters(
cluster._get_distance_matrix_radii_mic(),
bond_threshold,
min_samples=1,
)
# If the cluster cleaning fails, the cluster is not reported
try:
dbscan_clusters = matid.geometry.get_clusters(
cluster._get_distance_matrix_radii_mic(),
bond_threshold,
min_samples=1,
)
except Exception:
continue
largest_indices = max(dbscan_clusters, key=lambda x: len(x))
cluster.indices = np.array(cluster.indices)[largest_indices].tolist()
return clusters
clusters_cleaned.append(cluster)
return clusters_cleaned
2 changes: 0 additions & 2 deletions matid/core/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ def __init__(
self,
disp_tensor_mic,
disp_factors,
disp_tensor_finite,
dist_matrix_mic,
dist_matrix_radii_mic,
cell_list=None,
):
self.disp_tensor_mic = disp_tensor_mic
self.disp_factors = disp_factors
self.disp_tensor_finite = disp_tensor_finite
self.dist_matrix_mic = dist_matrix_mic
self.dist_matrix_radii_mic = dist_matrix_radii_mic
self.cell_list = cell_list
Loading

0 comments on commit 16b0b7b

Please sign in to comment.