Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan8be committed Apr 12, 2024
1 parent 039e145 commit ee61f88
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 183 deletions.
58 changes: 28 additions & 30 deletions metadynminer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2202,20 +2202,18 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):

print("Searching for the nearest local minima... ")
iteration = 0
old_m_fes = m_fes
while 0.0 in m_fes[:]:
iteration += 1
if iteration > 10000:
if iteration > max_iteration:
print("Warning: Maximum number of iterations reached when searching. ")
break
for i in range(self.fes.shape[0]):
m_fes[i] = m_fes[int(dirs[i])]
if np.all(np.equal(old_m_fes, m_fes)):
print("Warning: some of the FES bins were not associated to any local minimum. ")
break
old_m_fes = m_fes
if iteration <= 10000:
if iteration <= max_iteration:
print("Done.")
if 0.0 in m_fes[:]:
print("Warning: some of the FES bins were not associated to any local minimum. ")

self.minima = np.array(minima_list)
self.m_fes = m_fes

Expand Down Expand Up @@ -2255,19 +2253,22 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):
okoli[ii,jj] = self.fes[int(a_indexes[ii,jj,0]),int(a_indexes[ii,jj,1])]

m_i, m_j = np.unravel_index(np.argmin(okoli), okoli.shape, order='C')

dirs[i,j, 0] = a_indexes[m_i,m_j,0]
dirs[i,j, 1] = a_indexes[m_i,m_j,1]
if self.fes[i,j] == self.fes[int(a_indexes[m_i,m_j,0]), int(a_indexes[m_i, m_j, 1])] and not np.all(okoli == np.min(okoli)):
minima_count += 1
m_fes[i,j] = minima_count
min_cv1 = (((i)/self.res)*(cv1max-cv1min))+cv1min
min_cv2 = (((j)/self.res)*(cv2max-cv2min))+cv2min
minima_list.append([self.fes[i,j],i,j, min_cv1, min_cv2])

if not np.all(okoli == np.min(okoli)):
dirs[i,j, 0] = a_indexes[m_i,m_j,0]
dirs[i,j, 1] = a_indexes[m_i,m_j,1]
if self.fes[i,j] == self.fes[int(a_indexes[m_i,m_j,0]), int(a_indexes[m_i, m_j, 1])]:
minima_count += 1
m_fes[i,j] = minima_count
min_cv1 = (((i)/self.res)*(cv1max-cv1min))+cv1min
min_cv2 = (((j)/self.res)*(cv2max-cv2min))+cv2min
minima_list.append([self.fes[i,j],i,j, min_cv1, min_cv2])
else:
dirs[i,j, 0] = i
dirs[i,j, 1] = j

print("Searching for the nearest local minima... ")
iteration = 0
old_m_fes = m_fes
while 0.0 in m_fes[:,:]:
iteration += 1
if iteration > max_iteration:
Expand All @@ -2276,12 +2277,11 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):
for i in range(self.fes.shape[0]):
for j in range(self.fes.shape[1]):
m_fes[i,j] = m_fes[int(dirs[i,j,0]), int(dirs[i,j,1])]
if np.all(np.equal(old_m_fes, m_fes)):
print("Warning: some of the FES bins were not associated to any local minimum. ")
break
old_m_fes = m_fes
if iteration <= 10000:
print("Done.")
if iteration <= max_iteration:
print("Done.")
if 0.0 in m_fes[:,:]:
print("Warning: some of the FES bins were not associated to any local minimum. ")

self.minima = np.array(minima_list)
self.m_fes = m_fes

Expand Down Expand Up @@ -2338,22 +2338,20 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):

print("Searching for the nearest local minima... ")
iteration = 0
old_m_fes = m_fes
while 0.0 in m_fes[:,:,:]:
iteration += 1
if iteration > 10000:
if iteration > max_iteration:
print("Warning: Maximum number of iterations reached when searching. ")
break
for i in range(self.fes.shape[0]):
for j in range(self.fes.shape[1]):
for k in range(self.fes.shape[2]):
m_fes[i,j,k] = m_fes[int(dirs[i,j,k,0]), int(dirs[i,j,k,1]),int(dirs[i,j,k,2])]
if np.all(np.equal(old_m_fes, m_fes)):
print("Warning: some of the FES bins were not associated to any local minimum. ")
break
old_m_fes = m_fes
if iteration <= 10000:
if iteration <= max_iteration:
print("Done.")
if 0.0 in m_fes[:,:,:]:
print("Warning: some of the FES bins were not associated to any local minimum. ")

self.minima = np.array(minima_list)
self.m_fes = m_fes

Expand Down
12 changes: 6 additions & 6 deletions tests/test_fep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

def test_1p():
expected = np.array([ 385.17567651, 1528.33533688])
expected = np.array([ 385.17552302, 1528.3351816 ])
#load hills
h1 = mm.Hills(name="./data/acealanme1d", periodic=[True])
#find minima on FES
Expand All @@ -16,7 +16,7 @@ def test_1p():
assert(np.allclose(fep, expected, 1e-3))

def test_2p():
expected = np.array([ 371.9108889 , 629.40182382, 1252.17936501, 3040.47957346])
expected = np.array([ 371.91080136, 629.40164896, 1289.9170257, 1252.1794877, 3040.4783994 ])
#load hills
h2 = mm.Hills(name="./data/acealanme", periodic=[True, True])
#find minima on FES
Expand All @@ -27,10 +27,10 @@ def test_2p():
assert(np.allclose(fep, expected, 1e-3))

def test_3p():
expected = np.array([ -41.67918722, -135.41854014, 243.58920429, 1060.11504292,
2378.11540026, 6513.85008335, 6598.73851877, 6418.38484675,
7694.86520632, 7869.748866 , 8185.64504805, 8250.71152005,
9633.41481942, 12238.44803989])
expected = np.array([ -41.67860026, 243.58946343, 1237.95317909, 1060.11536049,
2378.11588445, 6418.3849335 , 6513.84977833, 7869.74886734,
7694.86571792, 8185.64534757, 8250.71114721, 9633.41434977,
12238.44830729])
#load hills
h3 = mm.Hills(name="./data/acealanme3d", periodic=[True, True, True])
#find minima on FES
Expand Down
Loading

0 comments on commit ee61f88

Please sign in to comment.