forked from enviPath/enviPy
[Fix] Compound Grouping, Identity prediction of enviFormer, Setting params (#337)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#337
This commit is contained in:
@ -769,7 +769,7 @@ class Compound(EnviPathModel, AliasMixin, ScenarioMixin, ChemicalIdentifierMixin
|
||||
num_structs = self.structures.count()
|
||||
stand_smiles = set()
|
||||
for structure in self.structures.all():
|
||||
stand_smiles.add(FormatConverter.standardize(structure.smiles))
|
||||
stand_smiles.add(FormatConverter.standardize(structure.smiles, remove_stereo=True))
|
||||
|
||||
if len(stand_smiles) != 1:
|
||||
logger.debug(
|
||||
@ -838,7 +838,7 @@ class Compound(EnviPathModel, AliasMixin, ScenarioMixin, ChemicalIdentifierMixin
|
||||
if parsed is None:
|
||||
raise ValueError("Given SMILES is invalid")
|
||||
|
||||
standardized_smiles = FormatConverter.standardize(smiles)
|
||||
standardized_smiles = FormatConverter.standardize(smiles, remove_stereo=True)
|
||||
|
||||
# Check if we find a direct match for a given SMILES
|
||||
if CompoundStructure.objects.filter(smiles=smiles, compound__package=package).exists():
|
||||
@ -911,7 +911,7 @@ class Compound(EnviPathModel, AliasMixin, ScenarioMixin, ChemicalIdentifierMixin
|
||||
if parsed is None:
|
||||
raise ValueError("Given SMILES is invalid")
|
||||
|
||||
standardized_smiles = FormatConverter.standardize(smiles)
|
||||
standardized_smiles = FormatConverter.standardize(smiles, remove_stereo=True)
|
||||
|
||||
is_standardized = standardized_smiles == smiles
|
||||
|
||||
@ -2011,19 +2011,23 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
# Clean for potential XSS
|
||||
name = nh3.clean(name, tags=s.ALLOWED_HTML_TAGS).strip()
|
||||
|
||||
is_generic_name = False
|
||||
if name is None or name == "":
|
||||
name = f"Pathway {Pathway.objects.filter(package=package).count() + 1}"
|
||||
is_generic_name = True
|
||||
|
||||
pw.name = name
|
||||
|
||||
if description is not None and description.strip() != "":
|
||||
pw.description = nh3.clean(description, tags=s.ALLOWED_HTML_TAGS).strip()
|
||||
|
||||
pw.predicted = predicted
|
||||
|
||||
pw.save()
|
||||
|
||||
try:
|
||||
# create root node
|
||||
Node.create(pw, smiles, 0)
|
||||
Node.create(pw, smiles, 0, name=name if not is_generic_name else None)
|
||||
except ValueError as e:
|
||||
# Node creation failed, most likely due to an invalid smiles
|
||||
# delete this pathway...
|
||||
@ -3445,10 +3449,17 @@ class EnviFormer(PackageBasedModel):
|
||||
for smile in smi.split(".")
|
||||
]
|
||||
)
|
||||
|
||||
if smi in canon_smiles:
|
||||
logger.debug(f"Found input SMILES={smi} in prediction results. Skipping...")
|
||||
continue
|
||||
|
||||
except ValueError: # This occurs when the predicted string is an invalid SMILES
|
||||
logging.info(f"EnviFormer predicted an invalid SMILES: {smi}")
|
||||
continue
|
||||
|
||||
res.append(PredictionResult([ProductSet([smi])], prob, None))
|
||||
|
||||
results.append(res)
|
||||
|
||||
return results
|
||||
@ -3587,7 +3598,7 @@ class EnviFormer(PackageBasedModel):
|
||||
)
|
||||
root_node = ".".join(
|
||||
[
|
||||
FormatConverter.standardize(smile)
|
||||
FormatConverter.standardize(smile, remove_stereo=True)
|
||||
for smile in root_node[0].default_node_label.smiles.split(".")
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user