Skip to content

Commit

Permalink
Update README.rst
Browse files Browse the repository at this point in the history
Added simple functionality into the readme
  • Loading branch information
Dingel321 authored Feb 22, 2024
1 parent 8093581 commit bc18553
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,79 @@ Navigate to the cloned repository and install the module
.. code:: bash
pip install .
pip install .
Simulating cryo-EM particles
-----------------------------
To simulate cryo-EM particles, you can use the CryoEmSimulator class. The class takes in a simulation config file and simulates cryo-EM particles based on the parameters specified in the config file.

.. code:: python
from cryo_sbi import CryoEmSimulator
simulator = CryoEmSimulator("path_to_simulation_config_file.json")
images, parameters = simulator.simulate(num_sim=10, return_parameters=True)
The simulation config file should be a json file with the following structure:

.. code:: json
{
"N_PIXELS": 128,
"PIXEL_SIZE": 1.5,
"SIGMA": [0.5, 5.0],
"MODEL_FILE": "path_to_models/models.pt",
"SHIFT": 25.0,
"DEFOCUS": [0.5, 2.0],
"SNR": [0.001, 0.5],
"AMP": 0.1,
"B_FACTOR": [1.0, 100.0]
}
Training an amortized posterior model
--------------------------------------
Training of an amortized posterior can be done using the train_npe_model command line utility. The utility takes in an image config file, a train config file, and other training parameters. The utility trains a neural network to approximate the posterior distribution of the parameters given the images.

.. code:: bash
train_npe_model \
--image_config_file path_to_simulation_config_file.json \
--train_config_file path_to_train_config_file.json\
--epochs 150 \
--estimator_file posterior.estimator \
--loss_file posterior.loss \
--n_workers 4 \
--simulation_batch_size 5120 \
--train_device cuda
The training config file should be a json file with the following structure:

.. code:: json
{
"EMBEDDING": "RESNET18",
"OUT_DIM": 256,
"NUM_TRANSFORM": 5,
"NUM_HIDDEN_FLOW": 10,
"HIDDEN_DIM_FLOW": 256,
"MODEL": "NSF",
"LEARNING_RATE": 0.0003,
"CLIP_GRADIENT": 5.0,
"THETA_SHIFT": 25,
"THETA_SCALE": 25,
"BATCH_SIZE": 256
}
Inference
---------
Sampling from the posterior distribution can be done using the sample_posterior function in the estimator_utils module. The function takes in an estimator, images, and other parameters and returns samples from the posterior distribution.

.. code:: python
import cryo_sbi.utils.estimator_utils as est_utils
samples = est_utils.sample_posterior(
estimator=posterior,
images=images,
num_samples=20000,
batch_size=100,
device="cuda",
)

0 comments on commit bc18553

Please sign in to comment.