|
19 | 19 | from datetime import datetime |
20 | 20 |
|
21 | 21 | from ensemble_md.utils import utils |
22 | | -from ensemble_md.utils import gmx_parser |
23 | 22 | from ensemble_md.ensemble_EXE import EnsembleEXE |
24 | 23 |
|
25 | 24 |
|
@@ -154,45 +153,64 @@ def main(): |
154 | 153 | # Note after `get_swapping_pattern`, `states_` and `weights_` won't be necessarily |
155 | 154 | # since they are updated by `get_swapping_pattern`. (Even if the function does not explicitly |
156 | 155 | # returns `states_` and `weights_`, `states_` and `weights_` can still be different after |
157 | | - # the use of the function.) Therefore, here we create copyes for `states_` and `weights_` |
| 156 | + # the use of the function.) Therefore, here we create copies for `states_` and `weights_` |
158 | 157 | # before the use of `get_swapping_pattern`, so we can use them in `histogram_correction`, |
159 | 158 | # `combine_weights` and `update_MDP`. |
160 | 159 | states = copy.deepcopy(states_) |
161 | 160 | weights = copy.deepcopy(weights_) |
162 | 161 | swap_pattern, swap_list = EEXE.get_swapping_pattern(dhdl_files, states_, weights_) # swap_list will only be used for modify_coords # noqa: E501 |
163 | 162 |
|
164 | | - # 3-3. Calculate the weights averaged since the last update of the Wang-Landau incrementor. |
165 | | - # Note that the averaged weights are used for histogram correction/weight combination. |
166 | | - # For calculating the acceptance ratio (inside get_swapping_pattern), final weights should be used. |
167 | | - if EEXE.N_cutoff != -1 or EEXE.w_combine is True: |
| 163 | + # 3-3. Perform histogram correction/weight combination |
| 164 | + if wl_delta != [None for i in range(EEXE.n_sim)]: # weight-updating |
| 165 | + print(f'\nCurrent Wang-Landau incrementors: {wl_delta}\n') |
| 166 | + |
| 167 | + # (1) First we prepare the weights to be combined. |
| 168 | + # Note that although averaged weights are sometimes used for histogram correction/weight combination, |
| 169 | + # the final weights are always used for calculating the acceptance ratio. |
| 170 | + if EEXE.N_cutoff != -1 or EEXE.w_combine is not None: |
168 | 171 | # Only when histogram correction/weight combination is needed. |
169 | 172 | weights_avg, weights_err = EEXE.get_averaged_weights(log_files) |
| 173 | + weights_input = EEXE.prepare_weights(weights_avg, weights) # weights_input is for weight combination # noqa: E501 |
170 | 174 |
|
171 | | - # 3-4. Perform histogram correction/weight combination |
172 | | - # Note that we never use final weights but averaged weights here. |
| 175 | + # (2) Now we perform histogram correction/weight combination. |
173 | 176 | # The product of this step should always be named as "weights" to be used in update_MDP |
174 | | - if wl_delta != [None for i in range(EEXE.n_sim)]: # weight-updating |
175 | | - print(f'\nCurrent Wang-Landau incrementors: {wl_delta}') |
176 | | - if EEXE.N_cutoff != -1 and EEXE.w_combine is True: |
| 177 | + if EEXE.N_cutoff != -1 and EEXE.w_combine is not None: |
177 | 178 | # perform both |
178 | | - weights_avg = EEXE.histogram_correction(weights_avg, counts) |
179 | | - weights, g_vec = EEXE.combine_weights(weights_avg) # inverse-variance weighting seems worse |
180 | | - EEXE.g_vecs.append(g_vec) |
181 | | - elif EEXE.N_cutoff == -1 and EEXE.w_combine is True: |
| 179 | + if weights_input is None: |
| 180 | + # Then only histogram correction will be performed |
| 181 | + print('Note: Weight combination is deactivated because the weights are too noisy.') |
| 182 | + weights = EEXE.histogram_correction(weights, counts) |
| 183 | + _ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combiend weights |
| 184 | + else: |
| 185 | + weights_preprocessed = EEXE.histogram_correction(weights_input, counts) |
| 186 | + if EEXE.verbose is True: |
| 187 | + print('Performing weight combination ...') |
| 188 | + else: |
| 189 | + print('Performing weight combination ...', end='') |
| 190 | + weights, g_vec = EEXE.combine_weights(weights_preprocessed) # inverse-variance weighting seems worse # noqa: E501 |
| 191 | + EEXE.g_vecs.append(g_vec) |
| 192 | + elif EEXE.N_cutoff == -1 and EEXE.w_combine is not None: |
182 | 193 | # only perform weight combination |
183 | | - print('\nNote: No histogram correction will be performed.') |
184 | | - weights, g_vec = EEXE.combine_weights(weights_avg) # inverse-variance weighting seems worse |
185 | | - EEXE.g_vecs.append(g_vec) |
186 | | - elif EEXE.N_cutoff != -1 and EEXE.w_combine is False: |
| 194 | + print('Note: No histogram correction will be performed.') |
| 195 | + if weights_input is None: |
| 196 | + print('Note: Weight combination is deactivated because the weights are too noisy.') |
| 197 | + _ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combined weights |
| 198 | + else: |
| 199 | + if EEXE.verbose is True: |
| 200 | + print('Performing weight combination ...') |
| 201 | + else: |
| 202 | + print('Performing weight combination ...', end='') |
| 203 | + weights, g_vec = EEXE.combine_weights(weights_input) # inverse-variance weighting seems worse |
| 204 | + EEXE.g_vecs.append(g_vec) |
| 205 | + elif EEXE.N_cutoff != -1 and EEXE.w_combine is None: |
187 | 206 | # only perform histogram correction |
188 | | - print('\nNote: No weight combination will be performed.') |
189 | | - weights = EEXE.histogram_correction(weights_avg, counts) |
| 207 | + print('Note: No weight combination will be performed.') |
| 208 | + weights = EEXE.histogram_correction(weights_input, counts) |
| 209 | + _ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combined weights |
190 | 210 | else: |
191 | | - weights_current = [gmx_parser.parse_log(log_files[i])[0][-1] for i in range(EEXE.n_sim)] |
192 | | - w_for_printing = EEXE.combine_weights(weights_current)[1] |
193 | | - print('\nNote: No histogram correction will be performed.') |
| 211 | + print('Note: No histogram correction will be performed.') |
194 | 212 | print('Note: No weight combination will be performed.') |
195 | | - print(f'The alchemical weights of all states: \n {list(np.round(w_for_printing, decimals=3))}') |
| 213 | + _ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combiend weights |
196 | 214 |
|
197 | 215 | # 3-5. Modify the MDP files and swap out the GRO files (if needed) |
198 | 216 | # Here we keep the lambda range set in mdp the same across different iterations in the same folder but swap out the gro file # noqa: E501 |
|
0 commit comments