Python API
High level overview of the Python API for the Ersilia Model Hub. Detailed information can be found in the API Reference.
Fetch
from ersilia.api import Model
mdl = Model(model="eos3b5e", verbose=True)
mdl.fetch()
By default, models are fetched from DockerHub. To specify other fetching modes, follow the CLI structure passing them as arguments (for example: mdl.fetch(from_github=True)
)
To know if a model is already fetched, you can use the following function:
mdl.is_fetched()
Serve
To serve the model, simply use:
mdl.serve()
The same flags specified in the CLI can be passed as arguments to the serve command to specify the caching functionalities and others. For more detailed information, see our API Reference.
Run
Unlike the CLI, the Python package only allows as input lists of strings. The output will automatically be converted to a pandas dataframe.
input_list = [
"C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]",
"CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"
]
df = mdl.run(input_list)
Info
To get the metadata of a model that is already served, use the info command, which will be saved as a dictionary.
info = mdl.info()
Example
The example command will generate a list of examples randomly by default unless another mode (deterministic
, predefined
) is specified.
example_list = mdl.example()
Close
Close the model after using it:
mdl.close()
Delete
Eliminate the model from your system, including docker images:
mdl.delete()
Using the with
statement
with
statementA more concise way to run prediction would be to use the with
clause, if the model is already fetched. The with clause will automatically serve and close the model.
from ersilia.api import Model
input_list = [
"C1=C(SC(=N1)SC2=NN=C(S2)N)[N+](=O)[O-]",
"CC(C)CC1=CC=C(C=C1)C(C)C(=O)O"
]
with Model("eos3b5e") as mdl:
df = mdl.run(input_list)
Catalog
This command allows users to access a catalog of models available either locally or in the Ersilia Model Hub. To access more information, set the argument more=True
.
from ersilia.api import Catalog
cat = Catalog()
df = cat.catalog(hub=False) # Local catalog
df = cat.catalog(hub=True) # Entire hub catalog
Last updated
Was this helpful?