Add method for fixing faulty SMILES strings

This commit is contained in:
Saul Johnson
2017-08-25 20:19:48 +01:00
parent d4b470023a
commit 868575488e
+13 -2
View File
@@ -39,6 +39,17 @@ class SmilesConverter
return $this->db !== null;
}
/**
* Attempts to fix any errors in a SMILES string and returns the result.
*
* @param string $smiles the SMILES string to fix
* @return string the fixed SMILES string
*/
private static function fixSmiles($smiles) {
$output = str_replace('|', '', $smiles); // Zap vertical bars.
return $output;
}
/**
* Converts a compound name to SMILES notation.
*
@@ -54,7 +65,7 @@ class SmilesConverter
if ($this->isCacheEnabled()) {
$cachedSmiles = $this->db->get('smiles', 'name', $encoded);
if ($cachedSmiles !== null) {
return $cachedSmiles;
return self::fixSmiles($cachedSmiles);
}
}
@@ -68,7 +79,7 @@ class SmilesConverter
if ($this->isCacheEnabled()) {
$this->db->insert(['name' => $encoded, 'smiles' => $smiles]); // Cache name for future.
}
return $smiles;
return self::fixSmiles($smiles);
}
// Request failed.