Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions multi-ego-basic.ff/aminoacids.rtp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
H H 0.000 0
CA CAH 0.000 0
CB CH2 0.000 0
CG C 0.000 0
CG CS 0.000 0
OD1 O 0.000 0
ND2 NT 0.000 0
C C 0.000 0
Expand Down Expand Up @@ -216,7 +216,7 @@
H H 0.000 0
CA CAH 0.000 0
CB CH2 0.000 0
CG C 0.000 0
CG CS 0.000 0
OD1 OM 0.000 0
OD2 OM 0.000 0
C C 0.000 0
Expand Down Expand Up @@ -356,7 +356,7 @@
CA CAH 0.000 0
CB CH2 0.000 0
CG CH2 0.000 0
CD C 0.000 0
CD CS 0.000 0
OE1 O 0.000 0
NE2 NT 0.000 0
C C 0.000 0
Expand Down Expand Up @@ -412,7 +412,7 @@
CA CAH 0.000 0
CB CH2 0.000 0
CG CH2 0.000 0
CD C 0.000 0
CD CS 0.000 0
OE1 OM 0.000 0
OE2 OM 0.000 0
C C 0.000 0
Expand Down
1 change: 1 addition & 0 deletions multi-ego-basic.ff/atomtypes.atp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CZ 11.01100 ; bare carbon
CH 13.01900 ; aromatic CH
CR 12.01100 ; aromatic C
CS 12.01100 ; aromatic C
CAH 12.01100 ; aliphatic or sugar CH-group
CH1 13.01900 ; aliphatic or sugar CH-group
CH1t 13.01900 ; aliphatic or sugar CH-group
Expand Down
1 change: 1 addition & 0 deletions multi-ego-basic.ff/ffnonbonded.itp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NE 7 0.000 0.000 A 0.0000000000 8.752940e-07
C 6 0.000 0.000 A 0.0000000000 2.598570e-06
CR 6 0.000 0.000 A 0.0000000000 2.598570e-06
CS 6 0.000 0.000 A 0.0000000000 2.598570e-06
CZ 6 0.000 0.000 A 0.0000000000 2.598570e-06
CH 6 0.000 0.000 A 0.0000000000 2.598570e-06
H 1 0.000 0.000 A 0.0000000000 3.239247e-09
Expand Down
627 changes: 326 additions & 301 deletions src/multiego/Minimum_CUTOFF_Manual_modif.csv

Large diffs are not rendered by default.

Binary file modified src/multiego/atdhisto.pkl
Binary file not shown.
8 changes: 8 additions & 0 deletions src/multiego/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import time
import re
import json
import matplotlib.pyplot as plt


from . import _term

Expand Down Expand Up @@ -356,6 +358,7 @@
)
meGO_LJ = sort_LJ(meGO_ensemble, meGO_LJ)
write_nonbonded(meGO_ensemble.topology_dataframe, meGO_LJ, parameters, output_dir)
save_matrix_png(output_dir)
write_output_readme(meGO_LJ, parameters, output_dir, stat_str)
return output_dir

Expand Down Expand Up @@ -389,6 +392,11 @@
f.write("\nContact parameters:\n")
f.write(stat_str)

def save_matrix_png(output_path):
# import matrix from type definition and use the class function to plot it
from .type_definitions import matrix
matrix.plot_energy_matrix(out_path=f"{output_path}/energy_matrix.png", show=False)


def print_stats(meGO_LJ):
# it would be nice to cycle over molecule types and print an half matrix with all the relevant information
Expand Down
63 changes: 31 additions & 32 deletions src/multiego/interaction_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ def find_class(self, module, name):

class InteractionMatrix:

def __init__(self, pkl_file, emax=0.16, c12_rep_df=None, pth=None, show=False):
def __init__(self, pkl_file, emax=0.16, c12_rep_df=None, pth=None, show=False, pth_bkbn=None, emax_bkbn=None):
self.atmat = self.read_pickle_file(pkl_file)
self.emax = emax
self.emax_bkbn = emax_bkbn if emax_bkbn is not None else emax
self.pth = pth
self.pth_bkbn = pth_bkbn if pth_bkbn is not None else pth
self.c12_rep_df = c12_rep_df
self.define_p_threshold()
self.nonlocal_matrix()
self.plot_energy_matrix(show=show)
if show:
self.plot_energy_matrix(show=show)

def roundPartial(self, value, resolution=0.005):
"""
Expand Down Expand Up @@ -61,7 +64,7 @@ def plot_energy_matrix(self, out_path = None, show = False):
bkbnd_atoms = ["C", "O", "N", "CAH", "CAH2", "H"]
attype_ordering_charged = [ "OM", "NL", "NZ"]
attype_ordering_polar = [ "NE", "NR", "NT", "OA", "CZ", "S", "SM", "SH", "CH2r", "CH1t"]
attype_ordering_apolar = ["CH1","CR", "CH", "CH2", "CH3"]
attype_ordering_apolar = ["CH1","CR", "CH", "CH2", "CH3", "CS"]



Expand Down Expand Up @@ -103,7 +106,7 @@ def plot_energy_matrix(self, out_path = None, show = False):

# Full normalization for the image
energy_matrix = np.array(energies).reshape(len(order_list_atom1), len(order_list_atom2))
norm = TwoSlopeNorm(vmin=-1,vcenter=0.07, vmax=self.emax)
norm = TwoSlopeNorm(vmin=-1,vcenter=0.07, vmax=np.maximum(self.emax, self.emax_bkbn))
# set -2 values to grey
energy_matrix = np.where(energy_matrix == -2, np.nan, energy_matrix)
# set nan values to grey
Expand All @@ -114,7 +117,7 @@ def plot_energy_matrix(self, out_path = None, show = False):
blue_part = cmap(np.linspace(0.5, 1, 256))
blue_cmap = LinearSegmentedColormap.from_list("blue_part", blue_part)

pos_norm = Normalize(vmin=0.07, vmax=self.emax)
pos_norm = Normalize(vmin=0.07, vmax=np.maximum(self.emax, self.emax_bkbn))
sm = ScalarMappable(norm=pos_norm, cmap=blue_cmap)
sm.set_array([]) # required for colorbar
ax.set_xticks(ticks=np.arange(len(order_list_atom2)), labels=order_list_atom2, rotation=90)
Expand Down Expand Up @@ -158,17 +161,15 @@ def read_pickle_file(self, filename):
tot_reps = []
sum_probs = []
for key in data.keys():
probs.append(data[key].p_repeats_n2)
#probs.append(data[key].p_density)
# probs.append(data[key].p_repeats_n2)
probs.append(data[key].p_density)
dists.append(data[key].exp_aver)
cutoffs.append(data[key].cutoff)
bins.append(data[key].xbins)
kde.append(data[key].kde)
tot_reps.append(data[key].tot_repeats)
sum_probs.append(np.sum(data[key].sum_probs))
atmat["probability"] = np.array(probs)
# atmat["probability"] = np.where(np.array(cutoffs) > 0 ,np.array(probs)/np.array(cutoffs)**2, np.array(probs))
# atmat["p_water"] =np.zeros(len(probs))
atmat["exp_aver"] = np.array(dists)
atmat["attype1"] = atmat["atom_pair"].str.split("_").str[0]
atmat["attype2"] = atmat["atom_pair"].str.split("_").str[1]
Expand All @@ -177,22 +178,19 @@ def read_pickle_file(self, filename):
atmat["kde"] = kde
atmat["tot_repeats"] = tot_reps
atmat["sum_probs"] = sum_probs
# atmat["probability"] = atmat["sum_probs"]/atmat["tot_repeats"]**(0.5*1.8) if np.sum(atmat["sum_probs"]) > 0 else 0
# fill nan values in probability with 0
atmat["probability"] = atmat["probability"].fillna(0)
# for all bkbn atom pairs set multiply the probability by 1.5 to increase the attractive interactions
bkbn_pairs = ["O_H", "O_O", "N_N", "C_C", "CAH_CAH", "CAH2_CAH2", "O_N", "O_C", "O_CAH","O_CAH2", "N_C","N_CAH", "C_CAH", "N_CAH2", "C_CAH2", "CAH_CAH2"]
#bkbn_pairs = ["O_H", "O_O", "N_N", "C_C", "CAH_CAH", "O_N", "O_C", "O_CAH", "N_C","N_CAH", "C_CAH" ]
for pair in bkbn_pairs:
atmat.loc[atmat["atom_pair"]==pair, "probability"] *= 2

# # for all bkbn atom pairs set multiply the probability by a factor f_bkbn to compansate for the different statistics
# bkbn_pairs = ["O_H", "O_O", "N_N", "C_C", "CAH_CAH", "CAH2_CAH2", "O_N", "O_C", "O_CAH","O_CAH2", "N_C","N_CAH", "C_CAH", "N_CAH2", "C_CAH2", "CAH_CAH2"]
# #bkbn_pairs = ["O_H", "O_O", "N_N", "C_C", "CAH_CAH", "O_N", "O_C", "O_CAH", "N_C","N_CAH", "C_CAH" ]
# for pair in bkbn_pairs:
# atmat.loc[atmat["atom_pair"]==pair, "probability"] *= self.f_bkbn
# where O-H set distance to 0.195
# atmat.loc[atmat["atom_pair"]=="O_H", "exp_aver"] = 0.195
# atmat.loc[atmat["atom_pair"]=="O_N", "exp_aver"] = 0.29
# atmat.loc[atmat["atom_pair"]=="C_N", "exp_aver"] = 0.41
ps = []
for i in range(len(atmat)):
ps.append((np.sum(kde[i]*np.diff(bins[i])[0]/bins[i]**2/ tot_reps[i] )))#* cutoffs[i]**3 )) )
# atmat["probability"] = np.array(ps)

return atmat


Expand Down Expand Up @@ -260,22 +258,23 @@ def define_special_nonlocal_dict(self):
return special_nonlocal_dict

def nonlocal_matrix(self):
self.atmat["energy"] = np.array(self.regall(self.atmat["probability"].to_numpy(), 1, self.emax, self.pth))
# self.atmat.loc[self.atmat["atom_pair"]=="O_H", "energy"] = 0.45
# self.atmat.loc[self.atmat["atom_pair"]=="O_N", "energy"] = 0.45
# self.atmat.loc[self.atmat["atom_pair"]=="N_C", "energy"] = 0.45
# eps_base = 0.08
# bkbn_pairs = ["O_O", "N_N", "C_C", "CAH_CAH", "CAH2_CAH2", "O_N", "O_C", "O_CAH","O_CAH2", "N_C","N_CAH", "C_CAH", "N_CAH2", "C_CAH2", "CAH_CAH2"]
# for pair in bkbn_pairs:
# if self.atmat.loc[self.atmat["atom_pair"]==pair, "energy"].values[0] < 0:
# self.atmat.loc[self.atmat["atom_pair"]==pair, "energy"] = eps_base


bkbn_pairs = [ "H_H", "O_O", "N_N", "C_C", "CAH_CAH", "CAH2_CAH2",
"O_N", "O_C", "O_CAH","O_CAH2", "O_H",
"N_C","N_CAH", "N_CAH2",
"C_CAH","C_CAH2",
"CAH_CAH2"]
# check that all bkbn_pairs are in the atmat dataframe
for pair in bkbn_pairs:
if pair not in self.atmat["atom_pair"].values:
raise ValueError(f"Atom pair {pair} not found in atmat dataframe.")

# self.atmat.loc[self.atmat["atom_pair"]=="O_O", "energy"] = 0.08
# self.atmat.loc[self.atmat["atom_pair"]=="N_N", "energy"] = 0.08
# self.atmat.loc[self.atmat["atom_pair"]=="C_C", "energy"] = 0.08
# where bkbn_pairs set probability pth to pth_bkbn and else to pth
self.atmat.loc[self.atmat["atom_pair"].isin(bkbn_pairs), "energy"] = np.array(self.regall(self.atmat.loc[self.atmat["atom_pair"].isin(bkbn_pairs), "probability"].to_numpy(), 1, self.emax_bkbn, self.pth_bkbn))
self.atmat.loc[~self.atmat["atom_pair"].isin(bkbn_pairs), "energy"] = np.array(self.regall(self.atmat.loc[~self.atmat["atom_pair"].isin(bkbn_pairs), "probability"].to_numpy(), 1, self.emax, self.pth))
#self.atmat["energy"] = np.array(self.regall(self.atmat["probability"].to_numpy(), 1, self.emax, self.pth))

self.special_nonlocal_dict = self.define_special_nonlocal_dict()



3 changes: 1 addition & 2 deletions src/multiego/pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def make_pairs_exclusion_topology(meGO_ensemble, args, meGO_LJ_14=None):
sbtype_to_atnum = reduced_topology.set_index("sb_type")["number"].to_dict()

nthbond = generate_bond_exclusions(reduced_topology, bond_pair)

# Build nth-bond (3 < bonds <= max_bond_separation) pair list.
# H-X pairs are skipped unless X is an allowed partner (e.g. H-CH2 is dropped).
# Default c12 is the combination rule; special overrides are applied afterwards.
Expand Down Expand Up @@ -147,7 +146,7 @@ def make_pairs_exclusion_topology(meGO_ensemble, args, meGO_LJ_14=None):
type_ai = pairs["ai"].map(meGO_ensemble.sbtype_type_dict)
type_aj = pairs["aj"].map(meGO_ensemble.sbtype_type_dict)

for types_i, types_j, c12_val in type_definitions.NTHBOND_C12_OVERRIDES:
for types_i, types_j, c12_val in type_definitions.NTHBOND_C12_OVERRIDES_4_5:
mask = type_ai.isin(types_i) & type_aj.isin(types_j)
if types_i != types_j:
mask |= type_ai.isin(types_j) & type_aj.isin(types_i)
Expand Down
33 changes: 22 additions & 11 deletions src/multiego/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"NE",
"C",
"CR",
"CS",
"CZ",
"CH",
"CH1",
Expand All @@ -74,7 +75,7 @@
"H",
"C0",
],
"at.num": [8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 16, 16, 16, 6, 15, 8, 6, 1, 20],
"at.num": [8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 16, 16, 16, 6, 15, 8, 6, 1, 20],
"rc_c12": [
2.5 * 0.262134**12, # "O", 2.631580e-07
2.5 * 0.253061**12, # "OM", 1.724403e-07
Expand All @@ -87,6 +88,7 @@
2.5 * 0.289746**12, # "NE", 8.752940e-07
2.5 * 0.317248**12, # "C", 2.598570e-06
2.5 * 0.317248**12, # "CR", 2.598570e-06
2.5 * 0.317248**12, # "CS", 2.598570e-06
2.5 * 0.317248**12, # "CZ", 2.598570e-06
2.5 * 0.317248**12, # "CH", 2.598570e-06
2.5 * 0.415167**12, # "CH1", 6.555574e-05
Expand Down Expand Up @@ -119,6 +121,7 @@
4.0 * 0.31365**12 * eps_NE, # "NE", sig=0.31365
4.0 * 0.35812**12 * eps_C, # "C", sig=0.35812
4.0 * 0.35812**12 * eps_C, # "CR", sig=0.35812
4.0 * 0.35812**12 * eps_C, # "CS", sig=0.35812
4.0 * 0.35812**12 * eps_CZ, # "CZ", sig=0.35812
4.0 * 0.35812**12 * eps_CH, # "CH", sig=0.35812
4.0 * 0.44592**12 * eps_CH1, # "CH1", sig=0.50192
Expand Down Expand Up @@ -149,7 +152,8 @@
4.0 * 0.31365**6 * eps_NZ, # "NZ",
4.0 * 0.31365**6 * eps_NE, # "NE",
4.0 * 0.35812**6 * eps_C, # "C",
4.0 * 0.35812**6 * eps_C, # "C",
4.0 * 0.35812**6 * eps_C, # "CR",
4.0 * 0.35812**6 * eps_C, # "CS",
4.0 * 0.35812**6 * eps_CZ, # "CZ",
4.0 * 0.35812**6 * eps_CH, # "CH"
4.0 * 0.44592**6 * eps_CH1, # "CH1"
Expand Down Expand Up @@ -359,17 +363,16 @@
)


EMAX = 0.15 #maximum epsilon value for the colorbar in the interaction matrix plot
P_TH = 0.0045#0.0034#0.46#0.009#0.008#0.12 # if P_TH is None it will be chosen in the InteractionMatrix class to have NL-NL repulsive
SHOW = True # if SHOW is True the interaction matrix will be plotted and saved in the current directory
# PKL = "atdhisto_density.pkl"
EMAX = 0.14 #maximum epsilon value for the colorbar in the interaction matrix plot
P_TH = 0.55#0.65#0.0034#0.46#0.009#0.008#0.12 # if P_TH is None it will be chosen in the InteractionMatrix class to have NL-NL repulsive
EMAX_BKBN = EMAX
P_TH_BKBN = 0.35
SHOW = False # if SHOW is True the interaction matrix will be plotted and saved in the current directory

PKL = "atdhisto.pkl"
matrix = InteractionMatrix(pkl_file=PKL, emax = EMAX, c12_rep_df = _c12_df, pth=P_TH, show=SHOW)
matrix = InteractionMatrix(pkl_file=PKL, emax = EMAX, c12_rep_df = _c12_df, pth=P_TH, pth_bkbn=P_TH_BKBN, show=SHOW, emax_bkbn=EMAX_BKBN)
special_non_local = matrix.special_nonlocal_dict
# print(len(special_non_local_A), len(special_non_local))
# print(special_non_local_A[0])
# print()
print(special_non_local[0])

# Verify that every attractive special interaction carries an epsilon at least
# as large as the global minimum. A violation here means the entry was
# mis-typed and would silently produce interactions weaker than the threshold
Expand Down Expand Up @@ -432,6 +435,14 @@
NTHBOND_C12_OVERRIDES = [
({str(row["atp1"]).strip()}, {str(row["atp2"]).strip()}, float(row["c12"])) for _, row in _c12_df.iterrows()
]

NTHBOND_C12_OVERRIDES_4_5 = NTHBOND_C12_OVERRIDES.copy() # Use the same overrides for 4-5 pairs for now
# Later should become this and use the 4-5 c12 when is much smaller than the >6 bond c12
# NTHBOND_C12_OVERRIDES_1_5 = [
# ({str(row["atp1"]).strip()}, {str(row["atp2"]).strip()}, float(row["c12.2"])) if float(row["c12.2"])*5 < float(row["c12.1"]) else
# ({str(row["atp1"]).strip()}, {str(row["atp2"]).strip()}, float(row["c12.1"])) for _, row in _c12_df.iterrows()
# ]

# NTHBOND_C12_OVERRIDES = [
# ({"O", "OM"}, {"O", "OM"}, mg_OO_c12_rep),
# ({"OM"}, {"OM"}, mg_OMOM_c12_rep),
Expand Down
Loading