asapdiscovery / asapdiscovery

Toolkit for open antiviral drug discovery by the ASAP Discovery Consortium
https://asapdiscovery.org
MIT License
30 stars 1 forks source link

Consider using pydantic aliases #387

Open jthorton opened 1 year ago

jthorton commented 1 year ago

I think we might be able to simplify the process of pairing internal schema names to the formatted postera names by using aliases in pydantic. See the class here for example, to work out what the the postera name is for the variable szybki_global_strain we have to check the function here then we have to map the enum name here. Using an alias would allow this to all be defined in a single place like so

from pydantic import BaseModel, Field

class SzybkiFreeformResult(BaseModel):
    """
    Class for storing the results of a Szybki Freeform conformer analysis run.
    """

    ligand_id: str = Field(..., serialization_alias="ligand_id")
    szybki_global_strain: float = Field(..., serialization_alias="ligand-global-strain-szybki-kcal-mol")

c = SzybkiFreeformResult(ligand_id="id_number1", szybki_global_strain="4")
print(c.model_dump(by_alias=True))

{'ligand_id': 'id_number1', 'ligand-global-strain-szybki-kcal-mol': 4.0}

cc @hmacdope

hmacdope commented 1 year ago

Yes please! This is a great idea. We will need to update the renaming methods in postera.manifold_data_validationto take a schema but I think this is a good change.