Skip to main content

Simulate a 3D electrostatic potential map from a PDB in pyTorch

Project description

ttsim3d

License PyPI Python Version CI codecov

Simulate 3D electrostatic potential maps from a PDB file in PyTorch. This package currently replicates theory laid out in Himes & Grigorieff (2021).

For a full list of changes, see the CHANGELOG.

Installation

ttsim3d is available on PyPi and can be installed via

pip install ttsim3d

From source

To create a source installation, first download/clone the repository, then run the install command

git clone https://github.com/teamtomo/ttsim3d.git
cd ttsim3d
pip install -e .

Optional development and testing dependencies can also be installed by running

pip install -e ".[dev,test]"

Running CLI program

Installation of the package creates the executable program ttsim3d-cli which takes in a PDB file along with other simulation options and outputs the simulated 3D scattering potential to a .mrc file. All options for the program can be printed by running:

ttsim3d-cli --help

Python objects

There are two user-facing classes in ttsim3d built upon Pydantic models for validating inputs and simulating a volume. The first class, ttsim3d.models.Simulator, holds reference to a PDB file and basic simulation parameters related to that structure. The second class, ttsim3d.models.SimulatorConfig is used to configure more advanced options, such as dose weighting and simulation upsampling. An basic use of these objects to run a simulation looks like

from ttsim3d.models import Simulator, SimulatorConfig

# Instantiate the configuration object 
sim_conf = SimulatorConfig(
    voltage=300.0,  # in keV
    apply_dose_weighting=True,
    dose_start=0.0,  # in e-/A^2
    dose_end=35.0,   # in e-/A^2
    upsampling=-1,   # auto
)

# Instantiate the simulator
sim = Simulator(
    pdb_filepath="some/path/to/structure.pdb",
    pixel_spacing=1.25,  # Angstroms
    volume_shape=(256, 256, 256),
    b_factor_scaling=1.0,
    additional_b_factor=15.0,  # Add to all atoms
    simulator_config=sim_conf,
)

# Run the simulation
volume = sim.run()
print(type(volume))  # torch.Tensor
print(volume.shape)  # (256, 256, 256)

# OR export the simulation to a mrc file
mrc_filepath = "some/path/to/simulated_structure/mrc"
sim.export_to_mrc(mrc_filepath)

Running on GPU or CPU

The ttsim3d package supports GPU accelerated simulations with PyTorch. Use the device argument to specify which device to run the simulation on.

# ...
# Assume same objects as above

# Run on the CPU
volume_cpu = sim.run(device="cpu")

# Run on the GPU (assumes CUDA is available)
# Both run on the zeroth GPU device
volume_gpu = sim.run(device="0")
volume_gpu = sim.run(device="cuda:0")

# Same argument can be passed to the `export_to_mrc` method
sim.export_to_mrc(mrc_filepath, device="cuda:0")

Working with configuration files

Simulation configurations can be saved to disk as either a YAML or JSON file by using the to_yaml or to_json methods of the Simulator class, respectively. Assuming the same sim object defined as above, you can export the configuration to a YAML file like this:

sim.to_yaml("some/path/to/simulation_config.yaml")

The contents of the YAML file will look something like this:

additional_b_factor: 15.0
b_factor_scaling: 1.0
center_atoms: true
pdb_filepath: some/path/to/structure.pdb
pixel_spacing: 1.25
remove_hydrogens: true
volume_shape:
- 256
- 256
- 256
simulator_config:
  apply_dose_weighting: true
  apply_dqe: true
  atom_batch_size: 16384
  crit_exposure_bfactor: -1
  dose_end: 35.0
  dose_filter_modify_signal: None
  dose_start: 0.0
  mtf_reference: k2_300kv
  store_volume: true
  upsampling: -1
  voltage: 300.0

Similarly, you can load in a configuration from a YAML file by using the from_yaml class method of the Simulator class:

from ttsim3d.models import Simulator

sim = Simulator.from_yaml("some/path/to/simulation_config.yaml")

Included MTF reference files

Users can specify MTF reference by a path to a star file under the SimulatorConfig.mtf_reference parameter. Applying a DQE filter during simulation can be turned on or off by the SimulatorConfig.apply_dqe parameter.

The ttsim3d package includes several common MTF reference files which are accessible by a string rather than a path. To see the list of included MTF reference files, run the following code snippet:

from ttsim3d import models

print(models.included_mtf_references())

The default MTF reference is "k2_300kV", which corresponds to the MTF of a Gatan K2 camera at 300 kV.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttsim3d-0.4.2.tar.gz (57.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttsim3d-0.4.2-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

Details for the file ttsim3d-0.4.2.tar.gz.

File metadata

  • Download URL: ttsim3d-0.4.2.tar.gz
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ttsim3d-0.4.2.tar.gz
Algorithm Hash digest
SHA256 20ffcc3d31e4e0c2d25a577d080d79a9bbf19f2db4241ac1c6dfc36cc3b09d00
MD5 c26f9cd3946a03ee203638d60cbcad11
BLAKE2b-256 2986b00b6262b8a25e78b72e6d46c7594eaa7767005df0092941b81c94543fa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttsim3d-0.4.2.tar.gz:

Publisher: ci.yml on teamtomo/ttsim3d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ttsim3d-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: ttsim3d-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ttsim3d-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c839570b1ec776e7258aedb6e209234199c7bce07e3ae56708a61a38bc609e65
MD5 a8929bbfe3b3db12394fe55f9d9dfbad
BLAKE2b-256 060ce8759e9cb88f31c3783b139b0300c253a1bf093f6e8e5a52cddb29c56bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ttsim3d-0.4.2-py3-none-any.whl:

Publisher: ci.yml on teamtomo/ttsim3d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page