feos-org / feos

FeOs - A Framework for Equations of State and Classical Density Functional Theory
Other
110 stars 22 forks source link

Create chemical record from SMILES using rdkit #191

Closed prehner closed 10 months ago

prehner commented 10 months ago

Replacement for #188

Adds ChemicalRecord.from_smiles that uses rdkit and a user-provided set of SMARTS to convert a SMILES string into a chemical record (including bonds).

ChemicalRecord.from_smiles("CCCOCC", smarts)
ChemicalRecord(
    identifier=Identifier(smiles=CCCOCC),
    segments=["CH3", "CH2", "OCH2", "CH2", "CH3"],
    bonds=[[0, 1], [1, 2], [2, 3], [3, 4]]
)

You can also pass an Identifier to directly fill out the remaining fields

ChemicalRecord.from_smiles(Identifier(name="1-propanol", smiles="CCCO"), smarts)
ChemicalRecord(
    identifier=Identifier(name=1-propanol, smiles=CCCO),
    segments=["CH3", "CH2", "CH2", "OH"],
    bonds=[[0, 1], [1, 2], [2, 3]]
)