Skip to content

Commit ee61f88

Browse files
committed
bug fix
1 parent 039e145 commit ee61f88

File tree

4 files changed

+184
-183
lines changed

4 files changed

+184
-183
lines changed

metadynminer/__init__.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,20 +2202,18 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):
22022202

22032203
print("Searching for the nearest local minima... ")
22042204
iteration = 0
2205-
old_m_fes = m_fes
22062205
while 0.0 in m_fes[:]:
22072206
iteration += 1
2208-
if iteration > 10000:
2207+
if iteration > max_iteration:
22092208
print("Warning: Maximum number of iterations reached when searching. ")
22102209
break
22112210
for i in range(self.fes.shape[0]):
22122211
m_fes[i] = m_fes[int(dirs[i])]
2213-
if np.all(np.equal(old_m_fes, m_fes)):
2214-
print("Warning: some of the FES bins were not associated to any local minimum. ")
2215-
break
2216-
old_m_fes = m_fes
2217-
if iteration <= 10000:
2212+
if iteration <= max_iteration:
22182213
print("Done.")
2214+
if 0.0 in m_fes[:]:
2215+
print("Warning: some of the FES bins were not associated to any local minimum. ")
2216+
22192217
self.minima = np.array(minima_list)
22202218
self.m_fes = m_fes
22212219

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

22572255
m_i, m_j = np.unravel_index(np.argmin(okoli), okoli.shape, order='C')
2258-
2259-
dirs[i,j, 0] = a_indexes[m_i,m_j,0]
2260-
dirs[i,j, 1] = a_indexes[m_i,m_j,1]
2261-
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)):
2262-
minima_count += 1
2263-
m_fes[i,j] = minima_count
2264-
min_cv1 = (((i)/self.res)*(cv1max-cv1min))+cv1min
2265-
min_cv2 = (((j)/self.res)*(cv2max-cv2min))+cv2min
2266-
minima_list.append([self.fes[i,j],i,j, min_cv1, min_cv2])
2256+
2257+
if not np.all(okoli == np.min(okoli)):
2258+
dirs[i,j, 0] = a_indexes[m_i,m_j,0]
2259+
dirs[i,j, 1] = a_indexes[m_i,m_j,1]
2260+
if self.fes[i,j] == self.fes[int(a_indexes[m_i,m_j,0]), int(a_indexes[m_i, m_j, 1])]:
2261+
minima_count += 1
2262+
m_fes[i,j] = minima_count
2263+
min_cv1 = (((i)/self.res)*(cv1max-cv1min))+cv1min
2264+
min_cv2 = (((j)/self.res)*(cv2max-cv2min))+cv2min
2265+
minima_list.append([self.fes[i,j],i,j, min_cv1, min_cv2])
2266+
else:
2267+
dirs[i,j, 0] = i
2268+
dirs[i,j, 1] = j
22672269

22682270
print("Searching for the nearest local minima... ")
22692271
iteration = 0
2270-
old_m_fes = m_fes
22712272
while 0.0 in m_fes[:,:]:
22722273
iteration += 1
22732274
if iteration > max_iteration:
@@ -2276,12 +2277,11 @@ def findminima2(self, temp=300.0, energy_unit="kJ/mol", max_iteration=10000):
22762277
for i in range(self.fes.shape[0]):
22772278
for j in range(self.fes.shape[1]):
22782279
m_fes[i,j] = m_fes[int(dirs[i,j,0]), int(dirs[i,j,1])]
2279-
if np.all(np.equal(old_m_fes, m_fes)):
2280-
print("Warning: some of the FES bins were not associated to any local minimum. ")
2281-
break
2282-
old_m_fes = m_fes
2283-
if iteration <= 10000:
2284-
print("Done.")
2280+
if iteration <= max_iteration:
2281+
print("Done.")
2282+
if 0.0 in m_fes[:,:]:
2283+
print("Warning: some of the FES bins were not associated to any local minimum. ")
2284+
22852285
self.minima = np.array(minima_list)
22862286
self.m_fes = m_fes
22872287

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

23392339
print("Searching for the nearest local minima... ")
23402340
iteration = 0
2341-
old_m_fes = m_fes
23422341
while 0.0 in m_fes[:,:,:]:
23432342
iteration += 1
2344-
if iteration > 10000:
2343+
if iteration > max_iteration:
23452344
print("Warning: Maximum number of iterations reached when searching. ")
23462345
break
23472346
for i in range(self.fes.shape[0]):
23482347
for j in range(self.fes.shape[1]):
23492348
for k in range(self.fes.shape[2]):
23502349
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])]
2351-
if np.all(np.equal(old_m_fes, m_fes)):
2352-
print("Warning: some of the FES bins were not associated to any local minimum. ")
2353-
break
2354-
old_m_fes = m_fes
2355-
if iteration <= 10000:
2350+
if iteration <= max_iteration:
23562351
print("Done.")
2352+
if 0.0 in m_fes[:,:,:]:
2353+
print("Warning: some of the FES bins were not associated to any local minimum. ")
2354+
23572355
self.minima = np.array(minima_list)
23582356
self.m_fes = m_fes
23592357

tests/test_fep.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

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

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

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

0 commit comments

Comments
 (0)