Skip to content

Commit 42a2cf3

Browse files
author
Richard Tran
committed
made hookean constraint optional
1 parent a385636 commit 42a2cf3

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

calculators/prediction_tools.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def add_hookean_constraint(image, des_rt = 2., rec_rt = 1., spring_constant=7.5,
7474
image.set_constraint(cons)
7575

7676

77-
def cal_slab_energy(data, calc, traj_output=False, debug=False,refixed=False):
77+
def cal_slab_energy(data, calc, traj_output=False, debug=False,refixed=False, add_spring=True):
7878

7979
testobj = Atoms(data.atomic_numbers, positions=data.pos, tags=data.tags,
8080
cell=data.cell.squeeze(), pbc=True)
@@ -95,9 +95,10 @@ def cal_slab_energy(data, calc, traj_output=False, debug=False,refixed=False):
9595
c = FixAtoms(mask=data.fixed)
9696
testobj.set_constraint(c)
9797

98-
# added spring constant to prevent massive
99-
# surface reconstruction and desorption
100-
add_hookean_constraint(testobj)
98+
if add_spring:
99+
# added spring constant to prevent massive
100+
# surface reconstruction and desorption
101+
add_hookean_constraint(testobj)
101102

102103
if traj_output == True:
103104
os.makedirs("./trajs", exist_ok=True)
@@ -120,10 +121,10 @@ def cal_slab_energy(data, calc, traj_output=False, debug=False,refixed=False):
120121
return unrelax_slab_energy, relax_slab_energy, forces, pos_relaxed
121122

122123

123-
def add_info(data, calc, debug=False, traj_output=False,refixed=False):
124+
def add_info(data, calc, debug=False, traj_output=False,refixed=False, add_spring=True):
124125

125126
unrelax_slab_energy, relax_slab_energy,forces, pos_relaxed = \
126-
cal_slab_energy(data, calc, traj_output=traj_output, debug=debug,refixed=refixed)
127+
cal_slab_energy(data, calc, traj_output=traj_output, debug=debug,refixed=refixed, add_spring=add_spring)
127128

128129
data.y = relax_slab_energy
129130
data.unrelax_energy = unrelax_slab_energy
@@ -140,7 +141,7 @@ class MyThread(threading.Thread):
140141
max_threads = 8
141142
thread_limiter = threading.BoundedSemaphore(max_threads)
142143

143-
def __init__(self, datalist, pathname, gpus=0, debug=False, skip_ads=None,refixed=False):
144+
def __init__(self, datalist, pathname, gpus=0, debug=False, skip_ads=None,refixed=False, add_spring=True):
144145

145146
threading.Thread.__init__(self)
146147

@@ -149,6 +150,7 @@ def __init__(self, datalist, pathname, gpus=0, debug=False, skip_ads=None,refixe
149150
self.gpus=gpus
150151
self.debug = debug
151152
self.refixed=refixed
153+
self.add_spring = add_spring
152154

153155
# Make a list of rid that have already been done and converged to be skipped
154156
if os.path.isfile(pathname):
@@ -182,7 +184,7 @@ def run(self):
182184
continue
183185
# run predictions here
184186
try:
185-
data = add_info(data, calc, debug=self.debug,refixed= self.refixed)
187+
data = add_info(data, calc, debug=self.debug,refixed= self.refixed, add_spring=self.add_spring)
186188
except RuntimeError:
187189
continue
188190
data_list_E.append(data)

calculators/run_predictions_from_lmdb.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def read_options():
2626
help="Number of GPUs available")
2727
parser.add_argument("-a", "--remove_ads", dest="remove_ads", type=str, default=None,
2828
help="Adsorbate to omit")
29-
29+
parser.add_argument("-s", "--add_spring", dest="add_spring", type=str, default=True,
30+
help="Whether or not to add Hookean constraints")
3031

3132
args = parser.parse_args()
3233

@@ -51,7 +52,7 @@ def read_options():
5152
lp = range(int(len(input_lmdb)/args.number_of_threads)*j,
5253
int(len(input_lmdb)/args.number_of_threads)*(1+j))
5354
thread = MyThread([input_lmdb[ii] for ii in lp], output_lmdb,
54-
args.gpus, debug=args.debug, skip_ads=args.remove_ads)
55+
args.gpus, debug=args.debug, skip_ads=args.remove_ads, add_spring=args.add_spring)
5556
thread.start()
5657
sys.stdout = open(os.devnull, "w")
5758

0 commit comments

Comments
 (0)