timothygrant80 / cisTEM

Other
32 stars 26 forks source link

Unhandled Exception Error When Simulating Micrograph Using Existing STAR File in cisTEM #464

Open phonchi opened 1 year ago

phonchi commented 1 year ago

Problem Description

Dear developers:

I've been working with the simulator from cisTEM and following the installation instructions described in issue #454. My aim is to simulate a micrograph using many particles from a STAR file. I've modified the bgal_flat.sh script from the tutorial materials to suit version 2.0.0-alpha-165-5a2a2e3. The script's primary purpose is to generate betgal_vacuum.mrc and its associated STAR file. The modifications and execution of this script were successful.

However, when using the generated STAR file (via the "Use an existing set of orientations" option) with a modified script, I encounter a termination error.

Steps to Reproduce

  1. Execute the modified bgal_flat.sh script to generate betgal_vacuum.mrc and its associated STAR file.
  2. Modify the script for the "Use an existing set of orientations" option and use the generated STAR file.
  3. Execute the modified script.

Expected Behavior

The script should generate the desired simulated micrograph using the orientations from the STAR file without errors.

Actual Behavior

The script terminates prematurely, with the log ending in:

Working on slice 0/50
iSlab 0 0 4
slab_oZ 2.000000 slab_nZ 5 rotated_oZ 125.000000
*** Caught unhandled unknown exception; terminating

Scripts and Logs

Script 1: (modified bgal_flat.sh script)

#/bin/bash

# Specify where your alphas version of cisTEM is installed. 
path_to_cistem="/usr/local/bin"

# Singulatiry can be run with "singularity shell" to give you an "interactive" env in the container.
# In this example, we instead execute a specific function in the container
function_to_execute="simulate"

# If you are running match_template, you need the --nv flag as below, if the flag is included and the machine has no gpus, it will not run.
# Singularity will bind your homedirectory, and should bind the PWD. Outside of this, it will not know about your filesystem
# If you want to give access (say your images are on nrs or a scratch disc somewhere, add the --bind directive.

#singularity exec --nv --bind /scratch_dublin/himesb /groups/himesb/notes/cisTEM_20210401 /cisTEM/bin/simulate

################################
# File things
################################
output_filename="betgal_vacuum.mrc"
input_pdb_file="bgal_flat.pdb" # the parser is fairly good with PDB format, but will probably break in some cases.
output_size=640 # pixels - if < 0 a hack to set a fixed size for 2d image simulation, if > 0 the size of a 3D reference volume to simulate.
n_threads=16 # Not so important for a a 3d, it will be fast either way.

################################
# Bluring things
################################
linear_scaling_of_PDB_bfactors=1.0 # make sure your model is reasonable i.e. the builder didn't set all bfactors to 50 or something. can be between 0 and 1
per_atom_bfactor=4.0 # add any bfactor to all atoms, may need to be increased since motion is not considered in the 3d simulation

################################
# Imaging things
################################
pixel_size=1.0
CS=2.7 # mm
KV=300 # kev
OA=100 # micron, objective aperture won't affect a 3D sim

wanted_defocus=3000  # Angstrom
minimum_thickness=250

exposure_per_frame=1.5 # e-/Ang^2 ;; Dose rate doesn't affect 3D sim (only 2d) here it is used with n_frames to get the total exposure
exposure_rate=3.0 # e-/ pixel /s
n_frames=1
pre_exposure=0 # If you've left off some early frames, account for that here
n_particles=1

water_scaling=1.0  # Linear scaling of water molecules - normally not used, except for demonstration purposes

################################
# Don't worry about things
################################
# There are some options that I plan to set as default, but due to the way things are written, need to be passed via command line args.
from_future_args=" --only-modify-signal-3d=2 --wgt=0.225" 

################################
# Optional things
################################
# --save-detector-wavefunction : this is the probability distribution (really the square complex modulus of the detector wavefunction)
# --skip-random-angles : when simulating a particle stack, the orientation is randomized. For this tutorial, we want a consistent view to compare different conditions
# --max_number_of_noise_particles=6

optional_args="--max_number_of_noise_particles=4 --do-perfect-reference"

################################
# Run the thing
################################

${path_to_cistem}/${function_to_execute} ${from_future_args} ${optional_args} << EOF
$output_filename
no
$output_size
$n_threads
$input_pdb_file
no
$pixel_size
$linear_scaling_of_PDB_bfactors
$per_atom_bfactor
no
$n_particles
no
$wanted_defocus
0
$exposure_per_frame
$exposure_rate
$n_frames
yes
$water_scaling
0.0
$KV
$CS
$OA
0.0
$pre_exposure
32
$minimum_thickness
5
0.0
2.0
0.1
0.0001
0.0
0.0
0.0
0.0
EOF

Script 2 (modified for existing orientations):

#/bin/bash

# Specify where your alphas version of cisTEM is installed. 
path_to_cistem="/usr/local/bin"

# Singulatiry can be run with "singularity shell" to give you an "interactive" env in the container.
# In this example, we instead execute a specific function in the container
function_to_execute="simulate"

# If you are running match_template, you need the --nv flag as below, if the flag is included and the machine has no gpus, it will not run.
# Singularity will bind your homedirectory, and should bind the PWD. Outside of this, it will not know about your filesystem
# If you want to give access (say your images are on nrs or a scratch disc somewhere, add the --bind directive.

#singularity exec --nv --bind /scratch_dublin/himesb /groups/himesb/notes/cisTEM_20210401 /cisTEM/bin/simulate

################################
# File things
################################
output_filename="betgal_vacuum2.mrc"
input_pdb_file="bgal_flat.pdb" # the parser is fairly good with PDB format, but will probably break in some cases.
output_size=640 # pixels - if < 0 a hack to set a fixed size for 2d image simulation, if > 0 the size of a 3D reference volume to simulate.
n_threads=1 # Not so important for a a 3d, it will be fast either way.

################################
# Bluring things
################################
linear_scaling_of_PDB_bfactors=1.0 # make sure your model is reasonable i.e. the builder didn't set all bfactors to 50 or something. can be between 0 and 1
per_atom_bfactor=4.0 # add any bfactor to all atoms, may need to be increased since motion is not considered in the 3d simulation

################################
# Imaging things
################################
pixel_size=1.0
CS=2.7 # mm
KV=300 # kev
OA=100 # micron, objective aperture won't affect a 3D sim

wanted_defocus=3000  # Angstrom
minimum_thickness=250

exposure_per_frame=1.5 # e-/Ang^2 ;; Dose rate doesn't affect 3D sim (only 2d) here it is used with n_frames to get the total exposure
exposure_rate=3.0 # e-/ pixel /s
n_frames=1
pre_exposure=0 # If you've left off some early frames, account for that here
n_particles=1

water_scaling=1.0  # Linear scaling of water molecules - normally not used, except for demonstration purposes

################################
# Don't worry about things
################################
# There are some options that I plan to set as default, but due to the way things are written, need to be passed via command line args.
from_future_args=" " 

################################
# Optional things
################################
# --save-detector-wavefunction : this is the probability distribution (really the square complex modulus of the detector wavefunction)
# --skip-random-angles : when simulating a particle stack, the orientation is randomized. For this tutorial, we want a consistent view to compare different conditions
# --max_number_of_noise_particles=6

optional_args=" --skip-random-angles --print-extra-info"

################################
# Run the thing
################################

${path_to_cistem}/${function_to_execute} ${from_future_args} ${optional_args} << EOF
$output_filename
no
$output_size
$n_threads
$input_pdb_file
no
$pixel_size
$linear_scaling_of_PDB_bfactors
$per_atom_bfactor
yes
betgal_vacuum.mrc.star
0
no
yes
$water_scaling
0.0
$KV
$CS
$OA
0.0
$pre_exposure
32
$minimum_thickness
5
0.0
2.0
0.1
0.0001
0.0
0.0
0.0
0.0
EOF

Log Output:

        **   Welcome to Simulator   **

             Version : 0.25
            Compiled : Jul 31 2023
     Library Version : 2.0.0-alpha-165-5a2a2e3
         From Branch : master
                Mode : Scripted

Output filename                                    : betgal_vacuum2.mrc
Make a 3d scattering potential?                    : no
Wanted output size                                 : 640
Number of threads                                  : 1
PDB file name                                      : bgal_flat.pdb
Add another type of particle?                      : no
Output pixel size (Angstroms)                      : 1.0
Linear scaling of per atom bFactor                 : 1.0
Per atom (xtal) bFactor added to all atoms         : 4.0
Use an existing set of orientations                : yes
cisTEM star file name                              : betgal_vacuum.mrc.star

Found 1 particles in the input star file
Create a particle stack rather than a micrograph?  : 0
Create a tilt-series as well?                      : no
Set expert options?                                : yes
Linear scaling water intensity                     : 1.0
fraction of the mean_defocus to add as astigmatism : 0.0
IGNORED with input star: Accelrating volatage (kV) : 300
IGNORED iwth input star: Spherical aberration constant in millimeters : 2.7
Objective aperture diameter in micron              : 100
Std deviation of error to use in shifts, astigmatism, rotations etc. : 0.0
Pre-exposure in electron/A^2                       : 0
minimum padding of images with solvent             : 32
minimum thickness in Z                             : 250
Propagation distance in angstrom                   : 5
Rotation of tilt-axis from Y (degrees)             : 0.0
Standard deviation on angles in plane (degrees)    : 2.0
Standard deviation on tilt-angles (degrees)        : 0.1
Standard deviation on magnification (fraction)     : 0.0001
IN constructor 2 and use_star_file = 1

There are 32824 non-water atoms in the specimen.

Current number of PDBs 1
Using extra phase shift of 0.000000 radians
DO NOT RANDOMIZE IS 1 asdf
size of phi is 1
zeroing angles 0
Got here emulate is 0.000000
IN constructor 1 and use_star_file = 1

There are 1 tilts
for Tilt 0, scaling the pixel size from 1.000 to 1.000
Scaling the mean_defocus by 1.000103 to match the def at 300 KeV

        for frame 0 the size neigborhood is 2

using neighborhood of 125.00 vox^3 for waters and 125.00 vox^3 for non-waters
Starting projected water calc with sizeN 5, 5

bFactor and leadterm and wavelength 8.500000 2.5664e-03 2.5664e-03 1.9685e-02
Finishing projected water calc

        for frame 0 the size of the specimen is 397, 442

                wanted size is 397

Padding based on image rotation is (1)
Current specimen is x,y,z 330,285,250
size pre rot padding 330 285 0.000000 rot
size post rot 1 padding 727 727 0.000000 rot
size post rot 2 padding 727 727 padX 397 padY 442 padZ 0 rot

        Drift for iTilt 0, iFrame 0 is 0.0000 Ang
Transforming and sorting on Z
Shift x, y, z: 0, 0, 0
Atoms per nm^3 31.422, vol (in Ang^3) 727.00 727.00 250.00
specimen volume is 1.321e+05 nm expecting 4.152e+06 waters
probablity_of_water_in_voxel_octent 0.996072
waters added 4.153e+06 (100.02%)
tilt angle in radians/deg 0.00e+00/0.00e+00 iFrame 0/1.000000
wZ 250 csZ 250,rotZ 250

flat thicknes, 250 and rotated_Z 250

Working on iTilt 0 at 0.000000 degrees for frame 0
rotated_Z 250 nSlabs 50

nSlabs 50
iSlab 6
lSlab 6
Working on slice 0/50
iSlab 0 0 4
slab_oZ 2.000000 slab_nZ 5 rotated_oZ 125.000000
*** Caught unhandled unknown exception; terminating

Environment Details

Request

Any insights or suggestions on resolving this issue would be greatly appreciated. Thanks!

bHimes commented 6 months ago

Hi @phonchi - sorry, I missed this issue when originally submitted.

Thank you for the clear report and repro conditions. I have not tested the simulator on WSL, but since it is just CPU based, I suspect it should work.

Is this something you are still working on?