Simulation

class simulation.tem_simulation.Simulation(config_file, base_coord_file, tiltseries_file, nonoise_tilts_file, global_stack_no, temp_dir, apix=None, defocus=5, template_configs='', template_coords='', coord_error=None)

A class to hold associated configurations and metadata for a run of the TEM-Simulator.

### Attributes passed in on initialization ###
config_file

The file path to the TEM-Simulation configuration input file

base_coord_file

The file path to the TEM-Simulator particle coordinates file to use as base orientations/locations

tiltseries_file

The output tiltseries file path

nonoise_tilts_file

The no-noise version of the output tiltseries file path

global_stack_no

The ID number of this simulated stack within the experiment

temp_dir

The directory to use to store temporary input files

apix

(optional) the APIX value to provide to the TEM-Simulator if a PDB source is used

### Other attributes ###
orientations

The orientations given to the particles of interest

positions

The positions given to the particles of interest

sim_log_file

The file path to use for the temporary TEM-Simulator log file

custom_data

Field that can be used to store custom Assembler-specific metadata which will be output to the metadata log

__convert_coordinates(coordinates)

Give particle coordinates provided in pixels, convert them to nanometers.

Returns: A list of lists [x, y, z] representing particle positions in nm.

__replace(pattern, subst)
Helper function to go through a text file and replace instances of a given pattern with the

provided replacement

Parameters
  • file_path – The text file to make the replacement in

  • pattern – The pattern to look to replace within the text file

  • subst – The string to substitute in for instances of the pattern

__replace_nonoise(pattern, subst)
Variant helper function of the __replace function used to replace the no-noise tiltseries

file path in the configs file, since it replaces just the second instance of the given pattern

Parameters
  • file_path – The text file to make the replacement in

  • pattern – The pattern to look for and replace the second instance of within the file

  • subst – The string to substitute in for the second instance of the pattern

__write_coord_file(coordinates, orientations)
Helper function to write out particle coordinates and orientations in the format expected

by TEM-Simulator for a particle set

Parameters
  • filename – The coordinates file to write out a particle set’s information to

  • coordinates – The list of particle coordinates to write out

  • orientations – The list of particle Euler angles (extrinsic ZXZ) to write out

__write_fiducials_particle_set_section(bead_occupancy)
Write out the “particleset” section for the gold fiducials, which uses the random

coordinates from the occupancy option for the TEM-simulator instead of the standard coordinates text files.

__write_particle_section(particle_name, source, voxel_size=0.283)
For a given particle set, write out the particle parameters segment for the TEM-Simulator

configuration file

Parameters
  • particle_name – The particle name assigned to this set

  • source – The source MRC or PDB file used to simulate the particle from

  • voxel_size – If passing a PDB source, a voxel size (apix, in nm) must be provided

__write_particle_set_section(particle_set, coord_file)
For a given particle set, write out the “particleset” parameters segment for the

TEM-Simulator configuration file

For more information on what a particle set is, refer to the TEM-Simulator manual.

Parameters
  • particle_set – The src.particle_set.ParticleSet object containing various particle set parameters

  • coord_file – The TEM-Simulator coordinates file to write out parameters to

add_orientation(orientation)

Append to the orientations attribute

Parameters

orientation – The intrinsic Euler angles (z1, x, z2) to append to the orientations list

create_fiducials(fiducials_source, bead_occupancy)

Set up the TEM-simulator configurations to generate randomly distributed gold fiducials

Parameters
  • fiducials_source – The MRC file designed to simulate gold fiducials

  • bead_occupancy – The TEM-Simulator occupancy value for the beads

create_particle_lists(particle_sets)

Read the particle coordinates in self.base_coord_file and return them as an array

Parameters

particle_sets – A list of src.particle_set.ParticleSet objects holding parameters to update TEM-Simulator configuration files with

edit_output_files()
Go into the actual TEM-Simulator input files and update the output and log file values to

be what is currently stored in the appropriate class attributes

extend_orientations(orientations)

Extend the orientations attribute with a given list of orientations

Parameters

orientations – A list of extrinsic Euler angles (z1, x, z2) to extend the orientations list by

extend_positions(positions)

Extend the positions attribute with a given list of positions

Parameters

positions – A list of positions (X, Y, Z) to extend the positions list by

get_metadata()

Get the important contents of the Simulation object in dictionary form (the non-temp files)

Returns: The attributes of the Simulation object in dictionary form, to be used as metadata

logging

get_num_particles()

Open the self.base_coord_file and get the number of particles for the simulation indicated

Returns: The number of particles indicated by the coordinates file

parse_coordinates()

Read the particle coordinates in self.base_coord_file and return them as an array

Returns: A dict of {

coordinates: list of lists [x, y, z] representing particle positions to record true_coordinateS: list of lists [x, y, z] representing particle positions to simulate

}

run_tem_simulator(tem_exec_path)
Given the executable path to the TEM-Simulator, run the simulation with the set-up

specified by current Simulation object attributes

Parameters

tem_exec_path – The full path to the executable for the TEM-Simulator software

set_custom_data(data)

Update the custom data field, which is directly recorded in the metadata logs. Can be used to keep track of information specific to custom Assemblers

Parameters

data – The data object that should be recorded in the metadata logs