Skip to content

Commit

Permalink
Massive speed up of extract cluster.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Nov 30, 2017
1 parent d412dcf commit d95488e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,13 @@
Change log
==========

v2017.11.30
-----------
* Fix for severe enumlib_caller bug. This causes enumerations not to be carried
out properly due to bad accounting of symmetry of ordered sites. It results
in too few orderings.
* New method to extract clusters of atoms from a Molecule based on bonds.

v2017.11.27
-----------
* Improvements to FEFF
Expand Down
16 changes: 10 additions & 6 deletions pymatgen/core/structure.py
Expand Up @@ -2227,15 +2227,19 @@ def extract_cluster(self, target_sites, **kwargs):
(Molecule) Cluster of atoms.
"""
cluster = list(target_sites)
others = [site for site in self if site not in cluster]
size = 0
while len(cluster) > size:
size = len(cluster)
for site in self:
if site not in cluster:
for site2 in cluster:
if CovalentBond.is_bonded(site, site2, **kwargs):
cluster.append(site)
break
new_others = []
for site in others:
for site2 in cluster:
if CovalentBond.is_bonded(site, site2, **kwargs):
cluster.append(site)
break
else:
new_others.append(site)
others = new_others
return Molecule.from_sites(cluster)


Expand Down

0 comments on commit d95488e

Please sign in to comment.