The below code in MeMoModel crashes when sum(mask) is <= 0. If that happens neutralized_charge_inchi does not get set as a key and subsequently the code in the loop that tries to access this key crashes the program
mask1 = ~pd.isna(mod1_inchis.Mol)
print("MASK", mask1)
if sum(mask1) > 0:
mod1_inchis.loc[mask1,'charge'] = mod1_inchis.loc[mask1,'Mol'].apply(Chem.GetFormalCharge)
mod1_inchis.loc[mask1,'neutralized_charge_inchi'] = mod1_inchis.loc[mask1,'Mol'].apply(NeutraliseCharges2Inchi)
else:
mod1_inchis["neutralized_charge_inchi"] = None
mod1_inchis["charge"] = None
mask2 = ~pd.isna(mod2_inchis.Mol)
if sum(mask2) > 0:
mod2_inchis.loc[mask2,'charge'] = mod2_inchis.loc[mask2,'Mol'].apply(Chem.GetFormalCharge)
mod2_inchis.loc[mask2,'neutralized_charge_inchi'] = mod2_inchis.loc[mask2,'Mol'].apply(NeutraliseCharges2Inchi)
else:
mod2_inchis["neutralized_charge_mol"] = None
mod2_inchis["charge"] = None
# go through the inchis of the second model and find the corresponding inchi in self
matches = {"met_id1" : [],
"met_id2" : [],
"inchi_score":[],
"inchi_string":[],
"charge_diff" : []}
# loop over the first models metabolites
for i in range(len(mod1_inchis)):
# get the first inchi
inchi1 = mod1_inchis.loc[i, "inchis"]
# check if there is acutally an inchi, or whether the metabolite has none
if inchi1 != None:
# assign the precalculated values for the inchi
mol1 = mod1_inchis.loc[i, "Mol"]
nminchi1 = mod1_inchis.loc[i, "normalized_inchi"]
ntchrinchi1 = mod1_inchis.loc[i, "neutralized_charge_inchi"]
charge1 = mod1_inchis.loc[i,"charge"]
id1 = mod1_inchis.loc[i,"met_id"]
The below code in MeMoModel crashes when
sum(mask)
is <= 0. If that happensneutralized_charge_inchi
does not get set as a key and subsequently the code in the loop that tries to access this key crashes the programMRE