Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcello-Sega committed Apr 25, 2024
1 parent 6b59283 commit 441f2f8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pytim/observables/topological_order_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def compute(self, inp, kargs=None):
Note that the observable stores also other information
in the class:
- neighbor: the index of the nearest neighbor at topological
- neighbors: the index of the nearest neighbor at topological
distance N. The distances to these neighbors are the values
of psi.
Expand Down Expand Up @@ -101,7 +101,6 @@ def compute(self, inp, kargs=None):
tree = KDTree(inp.positions,boxsize=box)
OO = tree.query_ball_tree(tree, 3.5)
self.inp = inp
ids = []
for i,neighs in enumerate(OO):
neigh_Os = inp[[a for a in neighs if a != i ]]
sel = inp[[a for a in neighs if a != i ]].residues.atoms
Expand All @@ -125,25 +124,27 @@ def compute(self, inp, kargs=None):
self.dist,self.predecessors = res

pairs = np.argwhere(self.dist==self.topological_distance)
self.pairs = pairs
# we use directed=True because we computed the matrix symmetrically
dists = np.linalg.norm(minimum_image(inp[pairs[:,0]].positions - inp[pairs[:,1]].positions,
inp.dimensions),axis=1)
self.dists =dists
# in some case (gas) a molecule might have no 4th neighbor, so we initialize
# psi with inf.
neighbor,psi=-np.ones(len(inp),dtype=int),np.inf*np.ones(len(inp),dtype=float)
neighbors,psi=-np.ones(len(inp),dtype=int),np.inf*np.ones(len(inp),dtype=float)

index = np.arange(len(inp))

for i in np.arange(len(inp)):
cond = np.where(pairs[:,0]==i)[0]
if len(cond) > 0:
amin = np.argmin(dists[cond])
neighbor[i],psi[i] = pairs[cond,1][amin], np.min(dists[cond])
neighbors[i],psi[i] = pairs[cond,1][amin], np.min(dists[cond])
# otherwise, there is no 4th neighbor, we keep the default value (inf)
self.psi = psi
self.neighbor = np.array(neighbor)
# so far neighbors and pairs are indices of the local array, now we store
# them as MDAnalysis indices
self.neighbors = self.inp.indices[neighbors]
self.pairs = self.inp.indices[pairs]
return self.psi

def path(self, start, end):
Expand Down

0 comments on commit 441f2f8

Please sign in to comment.