Commit e0865e2f authored by eric pellegrini's avatar eric pellegrini
Browse files

removed recursive parsing of XTD file

parent c19167d7
Pipeline #1690 passed with stages
in 10 minutes and 33 seconds
...@@ -154,24 +154,6 @@ class XTDFile(object): ...@@ -154,24 +154,6 @@ class XTDFile(object):
self._atoms[idx1]["bonded_to"].add(idx2) self._atoms[idx1]["bonded_to"].add(idx2)
self._atoms[idx2]["bonded_to"].add(idx1) self._atoms[idx2]["bonded_to"].add(idx1)
def _build_universe(self, idx, clustered, cluster):
"""
"""
clustered[idx] = True
cluster.append(idx)
at = self._atoms[idx]
for nidx in at["bonded_to"]:
if nidx in clustered:
continue
self._build_universe(nidx, clustered, cluster)
def build_universe(self): def build_universe(self):
if self._pbc: if self._pbc:
...@@ -180,36 +162,46 @@ class XTDFile(object): ...@@ -180,36 +162,46 @@ class XTDFile(object):
else: else:
self._universe = InfiniteUniverse() self._universe = InfiniteUniverse()
clustered = {} configuration = numpy.empty((self._nAtoms,3),dtype=numpy.float64)
nclusters = 0
cluster = [] clusters = {}
configuration = numpy.empty((self._nAtoms,3),dtype=numpy.float64) equivalences = {}
for idx in self._atoms.keys(): for idx,atom in self._atoms.items():
if idx in clustered: if not clusters.has_key(idx):
continue nclusters += 1
clusters[idx] = nclusters
self._build_universe(idx, clustered, cluster) for neighbor in atom["bonded_to"]:
if (neighbor in clusters) and (clusters[idx] != clusters[neighbor]):
equivalences[clusters[neighbor]] = equivalences.get(clusters[idx],clusters[idx])
clustername = collections.defaultdict(lambda : 0) clusters[neighbor] = clusters[idx]
ac = [] mergedClusters = {}
for idx in cluster: for idx,clusterId in clusters.items():
if equivalences.has_key(clusterId):
mergedClusters.setdefault(equivalences[clusterId],[]).append(idx)
else:
mergedClusters.setdefault(clusterId,[]).append(idx)
for k,indexes in mergedClusters.items():
atomCluster = AtomCluster([])
bruteFormula = collections.defaultdict(lambda : 0)
for idx in indexes:
element = self._atoms[idx]["element"] element = self._atoms[idx]["element"]
name = self._atoms[idx]["name"] name = self._atoms[idx]["name"]
at = Atom(element, name=name, xtdIndex=idx) at = Atom(element, name=name, xtdIndex=idx)
at.index = self._atoms[idx]["mmtk_index"] at.index = self._atoms[idx]["mmtk_index"]
configuration[at.index] = self._atoms[idx]["xyz"] configuration[at.index] = self._atoms[idx]["xyz"]
ac.append(at) atomCluster.atoms.append(at)
clustername[element] += 1 bruteFormula[element] += 1
clustername = "".join(["%s%d" % (k,v) for k,v in sorted(clustername.items())]) atomCluster.name = "".join(["%s%d" % (k,v) for k,v in sorted(bruteFormula.items())])
cluster = [] self._universe.addObject(atomCluster)
ac = AtomCluster(ac,name=clustername)
self._universe.addObject(ac)
if self._pbc: if self._pbc:
configuration = self._universe._boxToRealPointArray(configuration) configuration = self._universe._boxToRealPointArray(configuration)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment