pycistem 0.6.1__cp310-cp310-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycistem/__init__.py +9 -0
- pycistem/config.py +20 -0
- pycistem/core/__init__.py +1 -0
- pycistem/core/core.cpp +1070 -0
- pycistem/core/core.cpython-310-x86_64-linux-gnu.so +0 -0
- pycistem/core/database.cpp +408 -0
- pycistem/core/euler_search.cpp +72 -0
- pycistem/core/run_profiles.cpp +114 -0
- pycistem/database/__init__.py +301 -0
- pycistem/programs/__init__.py +10 -0
- pycistem/programs/_cistem_constants.py +23 -0
- pycistem/programs/apply_ctf.py +59 -0
- pycistem/programs/cistem_program.py +277 -0
- pycistem/programs/ctffind.py +254 -0
- pycistem/programs/estimate_beamtilt.py +60 -0
- pycistem/programs/match_template.py +325 -0
- pycistem/programs/reconstruct3d.py +79 -0
- pycistem/programs/refine_ctf.py +106 -0
- pycistem/programs/refine_template.py +157 -0
- pycistem/programs/refine_template_dev.py +35 -0
- pycistem/programs/refine_template_niko.py +124 -0
- pycistem/programs/resample.py +30 -0
- pycistem/programs/run_profile.py +17 -0
- pycistem/programs/unblur.py +247 -0
- pycistem/programs/unblur_patch.py +204 -0
- pycistem/utils/__init__.py +1 -0
- pycistem/utils/extract_particles.py +36 -0
- pycistem/utils/move_class_into_unbinned_particle_stack.py +34 -0
- pycistem/utils/order_by_class_occupancy.py +26 -0
- pycistem/utils/plot_class_occupancy.py +51 -0
- pycistem/utils/plot_classification_fsc_movie.py +90 -0
- pycistem/utils/plot_occupancy_by_condition.py +129 -0
- pycistem-0.6.1.dist-info/METADATA +258 -0
- pycistem-0.6.1.dist-info/RECORD +84 -0
- pycistem-0.6.1.dist-info/WHEEL +5 -0
- pycistem-0.6.1.dist-info/licenses/LICENSE +201 -0
- pycistem-0.6.1.dist-info/sboms/auditwheel.cdx.json +1 -0
- pycistem.libs/libXau-154567c4.so.6.0.0 +0 -0
- pycistem.libs/libXcomposite-9a78b2b5.so.1.0.0 +0 -0
- pycistem.libs/libXcursor-557eab0f.so.1.0.2 +0 -0
- pycistem.libs/libXdamage-45f20f14.so.1.1.0 +0 -0
- pycistem.libs/libXfixes-e3b7d94c.so.3.1.0 +0 -0
- pycistem.libs/libXi-9178a6bd.so.6.1.0 +0 -0
- pycistem.libs/libXinerama-6a3f4a3e.so.1.0.0 +0 -0
- pycistem.libs/libXrandr-9f75043e.so.2.2.0 +0 -0
- pycistem.libs/libatk-1-3e086f29.0.so.0.22810.1 +0 -0
- pycistem.libs/libblkid-a9167753.so.1.1.0 +0 -0
- pycistem.libs/libbz2-a1e77c99.so.1.0.6 +0 -0
- pycistem.libs/libcairo-dfbea965.so.2.11512.0 +0 -0
- pycistem.libs/libdatrie-584ecbbd.so.1.3.2 +0 -0
- pycistem.libs/libffi-3a37023a.so.6.0.2 +0 -0
- pycistem.libs/libfontconfig-dcb2ce6c.so.1.12.0 +0 -0
- pycistem.libs/libfreetype-2f3b32b6.so.6.16.1 +0 -0
- pycistem.libs/libfribidi-a2ddad26.so.0.4.0 +0 -0
- pycistem.libs/libgdk-x11-2-ae2f4865.0.so.0.2400.32 +0 -0
- pycistem.libs/libgdk_pixbuf-2-e875edac.0.so.0.3612.0 +0 -0
- pycistem.libs/libgio-2-54f4f0a9.0.so.0.5600.4 +0 -0
- pycistem.libs/libgmodule-2-a8eef785.0.so.0.5600.4 +0 -0
- pycistem.libs/libgmp-d944b113.so.10.3.2 +0 -0
- pycistem.libs/libgnutls-e5fc1c5f.so.30.28.2 +0 -0
- pycistem.libs/libgomp-e985bcbb.so.1.0.0 +0 -0
- pycistem.libs/libgraphite2-a2b39163.so.3.0.1 +0 -0
- pycistem.libs/libgtk-x11-2-76f42ab1.0.so.0.2400.32 +0 -0
- pycistem.libs/libharfbuzz-26b3d829.so.0.10705.0 +0 -0
- pycistem.libs/libhogweed-cd4c53be.so.4.5 +0 -0
- pycistem.libs/libidn2-2f4a5893.so.0.3.6 +0 -0
- pycistem.libs/libmount-ec61bd71.so.1.1.0 +0 -0
- pycistem.libs/libnettle-37944285.so.6.5 +0 -0
- pycistem.libs/libp11-kit-ac9dcd7e.so.0.3.0 +0 -0
- pycistem.libs/libpango-1-e80d1584.0.so.0.4200.3 +0 -0
- pycistem.libs/libpangocairo-1-e0e0fbcf.0.so.0.4200.3 +0 -0
- pycistem.libs/libpangoft2-1-1fa1613e.0.so.0.4200.3 +0 -0
- pycistem.libs/libpcre-0dd207b5.so.1.2.10 +0 -0
- pycistem.libs/libpcre2-8-516f4c9d.so.0.7.1 +0 -0
- pycistem.libs/libpixman-1-06469c37.so.0.38.4 +0 -0
- pycistem.libs/libpng16-748299c7.so.16.34.0 +0 -0
- pycistem.libs/libselinux-d0805dcb.so.1 +0 -0
- pycistem.libs/libtasn1-564de53e.so.6.5.5 +0 -0
- pycistem.libs/libthai-cd935638.so.0.3.0 +0 -0
- pycistem.libs/libunistring-05abdd40.so.2.1.0 +0 -0
- pycistem.libs/libuuid-95b83d40.so.1.3.0 +0 -0
- pycistem.libs/libxcb-5ddf6756.so.1.1.0 +0 -0
- pycistem.libs/libxcb-render-161c0eb5.so.0.0.0 +0 -0
- pycistem.libs/libxcb-shm-0be6dfbf.so.0.0.0 +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Union, List
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from pycistem.programs import cistem_program
|
|
8
|
+
from pycistem.programs._cistem_constants import socket_i_have_info, socket_job_result_queue, socket_send_next_job
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class Reconstruct3dParameters:
|
|
12
|
+
input_particle_stack: str
|
|
13
|
+
input_star_filename: str
|
|
14
|
+
input_reconstruction: str = "/dev/null"
|
|
15
|
+
output_reconstruction_1: str = "my_reconstruction1.mrc"
|
|
16
|
+
output_reconstruction_2: str = "my_reconstruction2.mrc"
|
|
17
|
+
output_reconstruction_filtered: str = "my_reconstruction_filtered.mrc"
|
|
18
|
+
output_resolution_statistics: str = "my_resolution_statistics.txt"
|
|
19
|
+
my_symmetry: str = "C1"
|
|
20
|
+
first_particle: int = 1
|
|
21
|
+
last_particle: int = 0
|
|
22
|
+
pixel_size: float = 1.0
|
|
23
|
+
molecular_mass_kDa: float = 300.0
|
|
24
|
+
inner_mask_radius: float = 0.0
|
|
25
|
+
outer_mask_radius: float = 150.0
|
|
26
|
+
resolution_limit_rec: float = 0.0
|
|
27
|
+
resolution_limit_ref: float = 0.0
|
|
28
|
+
score_weight_conversion: float = 5.0
|
|
29
|
+
score_threshold: float = 1.0
|
|
30
|
+
smoothing_factor: float = 1.0
|
|
31
|
+
padding : float = 1.0
|
|
32
|
+
normalize_particles: bool = True
|
|
33
|
+
adjust_scores: bool = True
|
|
34
|
+
invert_contrast: bool = False
|
|
35
|
+
exclude_blank_edges: bool = False
|
|
36
|
+
crop_images: bool = False
|
|
37
|
+
split_even_odd: bool = True
|
|
38
|
+
center_mass: bool = False
|
|
39
|
+
use_input_reconstruction: bool = False
|
|
40
|
+
threshold_input_3d: bool = True
|
|
41
|
+
dump_arrays: bool = False
|
|
42
|
+
dump_file_1: str = "my_dump_file1.dat"
|
|
43
|
+
dump_file_2: str = "my_dump_file2.dat"
|
|
44
|
+
correct_ewald_sphere: int = 0
|
|
45
|
+
max_threads: int = 1
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def handle_job_result_queue(reader, writer, logger):
|
|
49
|
+
|
|
50
|
+
length = await reader.readexactly(4)
|
|
51
|
+
number_of_bytes = int.from_bytes(length, byteorder="little")
|
|
52
|
+
results = await reader.readexactly(number_of_bytes)
|
|
53
|
+
return(results)
|
|
54
|
+
|
|
55
|
+
async def handle_socket_i_have_info(reader, writer, logger):
|
|
56
|
+
data = await reader.readexactly(4)
|
|
57
|
+
length = int.from_bytes(data, byteorder="little")
|
|
58
|
+
data = await reader.readexactly(length)
|
|
59
|
+
print(f"Info: {data.decode('utf-8')}")
|
|
60
|
+
|
|
61
|
+
async def handle_results(reader, writer, logger):
|
|
62
|
+
#logger.info("Handling results")
|
|
63
|
+
await reader.readexactly(4)
|
|
64
|
+
length = await reader.readexactly(4)
|
|
65
|
+
number_of_bytes = int.from_bytes(length, byteorder="little")
|
|
66
|
+
data = await reader.readexactly(number_of_bytes*4)
|
|
67
|
+
|
|
68
|
+
def run(parameters: Union[Reconstruct3dParameters,list[Reconstruct3dParameters]],**kwargs):
|
|
69
|
+
|
|
70
|
+
if not isinstance(parameters, list):
|
|
71
|
+
parameters = [parameters]
|
|
72
|
+
signal_handlers = {
|
|
73
|
+
socket_job_result_queue : handle_job_result_queue,
|
|
74
|
+
socket_i_have_info: handle_socket_i_have_info,
|
|
75
|
+
socket_send_next_job: handle_results
|
|
76
|
+
}
|
|
77
|
+
asyncio.run(cistem_program.run("reconstruct3d", parameters, signal_handlers=signal_handlers,**kwargs))
|
|
78
|
+
|
|
79
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Union
|
|
4
|
+
import numpy as np
|
|
5
|
+
import struct
|
|
6
|
+
import mrcfile
|
|
7
|
+
from functools import partial
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from pycistem.programs import cistem_program
|
|
11
|
+
from pycistem.programs._cistem_constants import socket_program_defined_result, socket_job_result_queue, socket_i_have_an_error
|
|
12
|
+
#from pycistem.core import Image
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class RefineCtfParameters:
|
|
16
|
+
input_particle_images: str
|
|
17
|
+
input_star_filename: str
|
|
18
|
+
input_reconstruction: str
|
|
19
|
+
input_reconstruction_statistics: str = "my_statistics.txt"
|
|
20
|
+
use_statistics: bool = False
|
|
21
|
+
ouput_star_filename: str = "/dev/null"
|
|
22
|
+
ouput_shift_filename: str = "/dev/null"
|
|
23
|
+
ouput_phase_difference_image: str = "/dev/null"
|
|
24
|
+
ouput_beamtilt_image: str = "/dev/null"
|
|
25
|
+
ouput_difference_image: str = "/dev/null"
|
|
26
|
+
first_particle: int = 0
|
|
27
|
+
last_particle: int = 0
|
|
28
|
+
pixel_size: float = 1.0
|
|
29
|
+
molecular_mass_kDa: float = 300.0
|
|
30
|
+
inner_mask_radius: float = 0.0
|
|
31
|
+
outer_mask_radius: float = 150.0
|
|
32
|
+
low_resolution_limit: float = 300.0
|
|
33
|
+
high_resolution_limit: float = 3.0
|
|
34
|
+
defocus_search_range: float = 500.0
|
|
35
|
+
defocus_step: float = 50.0
|
|
36
|
+
padding: float = 1.0
|
|
37
|
+
ctf_refinement: bool = False
|
|
38
|
+
beamtilt_refinement: bool = False
|
|
39
|
+
normalize_particles: bool = True
|
|
40
|
+
invert_contrast: bool = False
|
|
41
|
+
exclude_blank_edges: bool = True
|
|
42
|
+
normalize_input_3d: bool = True
|
|
43
|
+
threshold_input_3d: bool = False
|
|
44
|
+
job_number_from_gui: int = 0
|
|
45
|
+
expected_number_of_results_from_gui: int = 0
|
|
46
|
+
max_threads: int = 1
|
|
47
|
+
|
|
48
|
+
def get_np_arrays(bytes,o,i,x,y,numpix):
|
|
49
|
+
array = np.frombuffer(bytes,offset=o+i*numpix*4, count=numpix,dtype=np.float32).copy()
|
|
50
|
+
array = array.reshape((y,-1))
|
|
51
|
+
array = array[:,:x]
|
|
52
|
+
return array
|
|
53
|
+
|
|
54
|
+
async def handle_results(reader, writer, logger, parameters):
|
|
55
|
+
#logger.info("Handling results")
|
|
56
|
+
size_of_array= await reader.readexactly(4)
|
|
57
|
+
result_number= await reader.readexactly(4)
|
|
58
|
+
number_of_expected_results= await reader.readexactly(4)
|
|
59
|
+
number_of_floats = int.from_bytes(size_of_array, byteorder="little")
|
|
60
|
+
result_number = int.from_bytes(result_number, byteorder="little")
|
|
61
|
+
number_of_expected_results = int.from_bytes(number_of_expected_results, byteorder="little")
|
|
62
|
+
results = await reader.readexactly(number_of_floats*4)
|
|
63
|
+
x_dim = int(struct.unpack("<f",results[0:4])[0])
|
|
64
|
+
y_dim = int(struct.unpack("<f",results[4:8])[0])
|
|
65
|
+
num_pixels = int(struct.unpack("<f",results[8:12])[0])
|
|
66
|
+
images_to_process = int(struct.unpack("<f",results[12:16])[0])
|
|
67
|
+
voltage_kV = struct.unpack("<f",results[16:20])[0]
|
|
68
|
+
spherical_aberration_mm = struct.unpack("<f",results[20:24])[0]
|
|
69
|
+
phase_difference_image = get_np_arrays(results,24,0,x_dim,y_dim,num_pixels)
|
|
70
|
+
phase_difference_image_cistem = Image()
|
|
71
|
+
|
|
72
|
+
phase_difference_image_cistem.Allocate(x_dim,y_dim,1,False,True)
|
|
73
|
+
np.copyto(phase_difference_image_cistem.real_values , phase_difference_image)
|
|
74
|
+
phase_difference_image_cistem.DivideByConstant(images_to_process)
|
|
75
|
+
phase_difference_image_cistem.CosineMask(0.45, parameters[result_number].pixel_size / 20.0, False, False, 0.0)
|
|
76
|
+
phase_difference_image_cistem.QuickAndDirtyWriteSlice(parameters[result_number].ouput_phase_difference_image,1,True,0.0)
|
|
77
|
+
#mrcfile.write("test.mrc", phase_difference_image.astype(np.float32), overwrite=True)
|
|
78
|
+
return(results)
|
|
79
|
+
|
|
80
|
+
async def handle_job_result_queue(reader, writer, logger):
|
|
81
|
+
|
|
82
|
+
length = await reader.readexactly(4)
|
|
83
|
+
number_of_bytes = int.from_bytes(length, byteorder="little")
|
|
84
|
+
results = await reader.readexactly(number_of_bytes)
|
|
85
|
+
return(results)
|
|
86
|
+
|
|
87
|
+
async def handle_i_have_an_error(reader, writer, logger):
|
|
88
|
+
print("I have an error")
|
|
89
|
+
#number_of_bytes = int.from_bytes(length, byteorder="little")
|
|
90
|
+
number_of_bytes = 40
|
|
91
|
+
results = await reader.read(number_of_bytes)
|
|
92
|
+
print(results)
|
|
93
|
+
return(results)
|
|
94
|
+
|
|
95
|
+
def run(parameters: Union[RefineCtfParameters,list[RefineCtfParameters]],**kwargs):
|
|
96
|
+
|
|
97
|
+
if not isinstance(parameters, list):
|
|
98
|
+
parameters = [parameters]
|
|
99
|
+
for i, par in enumerate(parameters):
|
|
100
|
+
par.image_number_for_gui = i
|
|
101
|
+
signal_handlers = {
|
|
102
|
+
socket_program_defined_result : partial(handle_results,parameters=parameters),
|
|
103
|
+
socket_job_result_queue : handle_job_result_queue,
|
|
104
|
+
socket_i_have_an_error: handle_i_have_an_error
|
|
105
|
+
}
|
|
106
|
+
byte_results = asyncio.run(cistem_program.run("refine_ctf", parameters, signal_handlers=signal_handlers,**kwargs))
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import re
|
|
3
|
+
import struct
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pickle import FALSE
|
|
6
|
+
from typing import Union
|
|
7
|
+
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import starfile
|
|
10
|
+
|
|
11
|
+
from pycistem.database import get_image_info_from_db, get_tm_info_from_db
|
|
12
|
+
from pycistem.programs import cistem_program
|
|
13
|
+
from pycistem.programs._cistem_constants import socket_template_match_result_ready
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class RefineTemplateParameters:
|
|
18
|
+
input_search_image: str
|
|
19
|
+
input_reconstruction: str = "template.mrc"
|
|
20
|
+
pixel_size: float = 1.0
|
|
21
|
+
voltate_kV: float = 300.0
|
|
22
|
+
spherical_aberration_mm: float = 2.7
|
|
23
|
+
amplitude_contrast: float = 0.07
|
|
24
|
+
defocus1: float = 10000
|
|
25
|
+
defocus2: float = 10000
|
|
26
|
+
defocus_angle: float = 0.0
|
|
27
|
+
angular_step: float = 0.2
|
|
28
|
+
defocus_search_range: float = 200.0
|
|
29
|
+
defocus_search_step: float = 10.0
|
|
30
|
+
padding: float = 1.0
|
|
31
|
+
mask_radius: float = 0.0
|
|
32
|
+
phase_shift: float = 0.0
|
|
33
|
+
mip_input_filename: str = "input_mip.mrc"
|
|
34
|
+
scaled_mip_input_filename: str = "input_scaled_mip.mrc"
|
|
35
|
+
best_psi_input_filename: str = "input_psi.mrc"
|
|
36
|
+
best_theta_input_filename: str = "input_theta.mrc"
|
|
37
|
+
best_phi_input_filename: str = "input_phi.mrc"
|
|
38
|
+
best_defocus_input_filename: str = "input_defocus.mrc"
|
|
39
|
+
best_psi_output_file: str = "/tmp/psi.mrc"
|
|
40
|
+
best_theta_output_file: str = "/tmp/theta.mrc"
|
|
41
|
+
best_phi_output_file: str = "/tmp/phi.mrc"
|
|
42
|
+
best_defocus_output_file: str = "/tmp/defocus.mrc"
|
|
43
|
+
mip_output_file: str = "/tmp/mip.mrc"
|
|
44
|
+
scaled_mip_output_file: str = "/tmp/scaled_mip.mrc"
|
|
45
|
+
wanted_threshold: float = 7.5
|
|
46
|
+
min_peak_radius: float = 10.0
|
|
47
|
+
xy_change_threshold: float = 10.0
|
|
48
|
+
exclude_above_xy_threshold: bool = False
|
|
49
|
+
in_plane_angular_step: float = 0.1
|
|
50
|
+
image_number_for_gui: int = 0
|
|
51
|
+
number_of_jobs_per_image_in_gui: int = 0
|
|
52
|
+
result_number: int = 1
|
|
53
|
+
max_threads: int = 1
|
|
54
|
+
directory_for_results: str = "/tmp"
|
|
55
|
+
threshold_for_result_plotting: float = 8.0
|
|
56
|
+
filename_for_gui_result_image: str = "/tmp/gui_result.mrc"
|
|
57
|
+
xyz_coords_filename: str ="/tmp/test.txt"
|
|
58
|
+
read_coordinates: bool = False
|
|
59
|
+
|
|
60
|
+
async def handle_results(reader, writer, logger):
|
|
61
|
+
#logger.info("Handling results")
|
|
62
|
+
data = await reader.read(4)
|
|
63
|
+
number_of_bytes = int.from_bytes(data[0:3], byteorder="little")
|
|
64
|
+
results = await reader.read(number_of_bytes)
|
|
65
|
+
return(results)
|
|
66
|
+
|
|
67
|
+
signal_handlers = {
|
|
68
|
+
socket_template_match_result_ready : handle_results
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
def parameters_from_database(database, image_asset_id, template_match_id, **kwargs):
|
|
72
|
+
image_info = get_image_info_from_db(database, image_asset=image_asset_id)
|
|
73
|
+
if image_info is None:
|
|
74
|
+
return None
|
|
75
|
+
tm_info = get_tm_info_from_db(database,image_asset_id, template_match_id)
|
|
76
|
+
if tm_info is None:
|
|
77
|
+
return(None)
|
|
78
|
+
par = RefineTemplateParameters(input_search_image=image_info["FILENAME"],
|
|
79
|
+
pixel_size=image_info["image_pixel_size"],
|
|
80
|
+
voltate_kV=image_info["VOLTAGE"],
|
|
81
|
+
spherical_aberration_mm=image_info["SPHERICAL_ABERRATION"],
|
|
82
|
+
amplitude_contrast=image_info["AMPLITUDE_CONTRAST"],
|
|
83
|
+
defocus1=image_info["DEFOCUS1"],
|
|
84
|
+
defocus2=image_info["DEFOCUS2"],
|
|
85
|
+
defocus_angle=image_info["DEFOCUS_ANGLE"],
|
|
86
|
+
mip_input_filename=tm_info["MIP_OUTPUT_FILE"],
|
|
87
|
+
scaled_mip_input_filename=tm_info["SCALED_MIP_OUTPUT_FILE"],
|
|
88
|
+
best_defocus_input_filename=tm_info["DEFOCUS_OUTPUT_FILE"],
|
|
89
|
+
best_psi_input_filename=tm_info["PSI_OUTPUT_FILE"],
|
|
90
|
+
best_theta_input_filename=tm_info["THETA_OUTPUT_FILE"],
|
|
91
|
+
best_phi_input_filename=tm_info["PHI_OUTPUT_FILE"],
|
|
92
|
+
**kwargs)
|
|
93
|
+
return(par)
|
|
94
|
+
|
|
95
|
+
def run(parameters: Union[RefineTemplateParameters,list[RefineTemplateParameters]],**kwargs):
|
|
96
|
+
|
|
97
|
+
if not isinstance(parameters, list):
|
|
98
|
+
parameters = [parameters]
|
|
99
|
+
|
|
100
|
+
byte_results = asyncio.run(cistem_program.run("refine_template", parameters, signal_handlers=signal_handlers,**kwargs))
|
|
101
|
+
#File names of original image file name, 3D template file name, energy, Cs, amp. contrast, phase shift, X, Y position, Euler angles, defocus 1 & 2 & angle, pixel size, CC average, CC STD, SNR, scaled SNR
|
|
102
|
+
result_peaks = pd.DataFrame({
|
|
103
|
+
"image_filename": pd.Series(dtype="object"),
|
|
104
|
+
"template_filename": pd.Series(dtype="object"),
|
|
105
|
+
"energy": pd.Series(dtype="float"),
|
|
106
|
+
"Cs": pd.Series(dtype="float"),
|
|
107
|
+
"amplitude_contrast": pd.Series(dtype="float"),
|
|
108
|
+
"phase_shift": pd.Series(dtype="float"),
|
|
109
|
+
"defocus1": pd.Series(dtype="float"),
|
|
110
|
+
"defocus2": pd.Series(dtype="float"),
|
|
111
|
+
"defocus_angle": pd.Series(dtype="float"),
|
|
112
|
+
"peak_number": pd.Series(dtype="int"),
|
|
113
|
+
"x": pd.Series(dtype="float"),
|
|
114
|
+
"y": pd.Series(dtype="float"),
|
|
115
|
+
"psi": pd.Series(dtype="float"),
|
|
116
|
+
"theta": pd.Series(dtype="float"),
|
|
117
|
+
"phi": pd.Series(dtype="float"),
|
|
118
|
+
"defocus": pd.Series(dtype="float"),
|
|
119
|
+
"pixel_size": pd.Series(dtype="float"),
|
|
120
|
+
"peak_value": pd.Series(dtype="float")
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
for parameter_index,byte_result in byte_results:
|
|
124
|
+
struct.unpack_from("<i",byte_result,offset=0)[0]
|
|
125
|
+
peak_numbers = struct.unpack_from("<i",byte_result,offset=4)[0]
|
|
126
|
+
struct.unpack_from("<i",byte_result,offset=8)[0]
|
|
127
|
+
struct.unpack_from("<f",byte_result,offset=12)[0]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
for peak_number in range(peak_numbers):
|
|
131
|
+
(x, y, psi, theta, phi, defocus, pixel_size, peak_height) = struct.unpack_from("<ffffffff",byte_result,offset=16+peak_number*32)
|
|
132
|
+
new_peak_series = pd.Series([
|
|
133
|
+
parameters[parameter_index].input_search_image,
|
|
134
|
+
parameters[parameter_index].input_reconstruction,
|
|
135
|
+
parameters[parameter_index].voltate_kV,
|
|
136
|
+
parameters[parameter_index].spherical_aberration_mm,
|
|
137
|
+
parameters[parameter_index].amplitude_contrast,
|
|
138
|
+
parameters[parameter_index].phase_shift,
|
|
139
|
+
parameters[parameter_index].defocus1,
|
|
140
|
+
parameters[parameter_index].defocus2,
|
|
141
|
+
parameters[parameter_index].defocus_angle,
|
|
142
|
+
int(peak_number),
|
|
143
|
+
x,
|
|
144
|
+
y,
|
|
145
|
+
psi,
|
|
146
|
+
theta,
|
|
147
|
+
phi,
|
|
148
|
+
defocus,
|
|
149
|
+
pixel_size,
|
|
150
|
+
peak_height], index = result_peaks.columns)
|
|
151
|
+
result_peaks.loc[len(result_peaks.index)] = new_peak_series
|
|
152
|
+
|
|
153
|
+
return(result_peaks)
|
|
154
|
+
|
|
155
|
+
def write_starfile(results,filename, overwrite=True):
|
|
156
|
+
# Write the results dataframe to a star file
|
|
157
|
+
starfile.write(results, filename=filename, overwrite=overwrite)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import asyncio
|
|
3
|
+
import pycistem.programs.cistem_program as cistem_program
|
|
4
|
+
from typing import Union
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class RefineTemplateDevParameters:
|
|
8
|
+
input_starfile: str = "input.star"
|
|
9
|
+
output_starfile: str = "output.star"
|
|
10
|
+
input_template: str = "input.mrc"
|
|
11
|
+
start_position:int = 0
|
|
12
|
+
end_position:int = -1
|
|
13
|
+
num_threads:int = 1
|
|
14
|
+
|
|
15
|
+
def run(parameters: Union[RefineTemplateDevParameters,list[RefineTemplateDevParameters]],write_directly_to_db=True,**kwargs):
|
|
16
|
+
|
|
17
|
+
if not isinstance(parameters, list):
|
|
18
|
+
parameters = [parameters]
|
|
19
|
+
|
|
20
|
+
signal_handlers = {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
results = asyncio.run(cistem_program.run("refine_template_dev", parameters, signal_handlers=signal_handlers,num_threads=parameters[0].num_threads,**kwargs))
|
|
25
|
+
|
|
26
|
+
return(results)
|
|
27
|
+
|
|
28
|
+
async def run_async(parameters: Union[RefineTemplateDevParameters,list[RefineTemplateDevParameters]],**kwargs):
|
|
29
|
+
|
|
30
|
+
if not isinstance(parameters, list):
|
|
31
|
+
parameters = [parameters]
|
|
32
|
+
|
|
33
|
+
result = await cistem_program.run("refine_template_dev", parameters,num_threads=parameters[0].num_threads,**kwargs)
|
|
34
|
+
|
|
35
|
+
return(result)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import struct
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pickle import FALSE
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
from pycistem.database import get_image_info_from_db, get_tm_info_from_db
|
|
9
|
+
from pycistem.programs import cistem_program
|
|
10
|
+
from pycistem.programs._cistem_constants import socket_template_match_result_ready
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class RefineTemplateParameters:
|
|
15
|
+
input_search_image: str
|
|
16
|
+
input_reconstruction: str = "template.mrc"
|
|
17
|
+
pixel_size: float = 1.0
|
|
18
|
+
voltate_kV: float = 300.0
|
|
19
|
+
spherical_aberration_mm: float = 2.7
|
|
20
|
+
amplitude_contrast: float = 0.07
|
|
21
|
+
defocus1: float = 10000
|
|
22
|
+
defocus2: float = 10000
|
|
23
|
+
defocus_angle: float = 0.0
|
|
24
|
+
low_resolution_limit: float = 300.0
|
|
25
|
+
high_resolution_limit: float = 3.0
|
|
26
|
+
angular_range: float = 0.2
|
|
27
|
+
angular_step: float = 0.2
|
|
28
|
+
best_parameters_to_keep: int = 20
|
|
29
|
+
defocus_search_range: float = 200.0
|
|
30
|
+
defocus_search_step: float = 10.0
|
|
31
|
+
pixel_size_search_range: float = 0.0
|
|
32
|
+
pixel_size_step: float = 0.01
|
|
33
|
+
padding: float = 1.0
|
|
34
|
+
ctf_refinement: bool = True
|
|
35
|
+
mask_radius: float = 0.0
|
|
36
|
+
phase_shift: float = 0.0
|
|
37
|
+
mip_input_filename: str = "input_mip.mrc"
|
|
38
|
+
scaled_mip_input_filename: str = "input_scaled_mip.mrc"
|
|
39
|
+
best_psi_input_filename: str = "input_psi.mrc"
|
|
40
|
+
best_theta_input_filename: str = "input_theta.mrc"
|
|
41
|
+
best_phi_input_filename: str = "input_phi.mrc"
|
|
42
|
+
best_defocus_input_filename: str = "input_defocus.mrc"
|
|
43
|
+
best_pixel_size_input_filename: str = "input_pixel_size.mrc"
|
|
44
|
+
best_psi_output_file: str = "/tmp/psi.mrc"
|
|
45
|
+
best_theta_output_file: str = "/tmp/theta.mrc"
|
|
46
|
+
best_phi_output_file: str = "/tmp/phi.mrc"
|
|
47
|
+
best_defocus_output_file: str = "/tmp/defocus.mrc"
|
|
48
|
+
best_pixel_size_output_file: str = "/tmp/pixel_size.mrc"
|
|
49
|
+
mip_output_file: str = "/tmp/mip.mrc"
|
|
50
|
+
scaled_mip_output_file: str = "/tmp/scaled_mip.mrc"
|
|
51
|
+
wanted_threshold: float = 7.5
|
|
52
|
+
min_peak_radius: float = 10.0
|
|
53
|
+
xy_change_threshold: float = 10.0
|
|
54
|
+
exclude_above_xy_threshold: bool = False
|
|
55
|
+
my_symmetry: str = "C1"
|
|
56
|
+
in_plane_angular_step: float = 0.1
|
|
57
|
+
first_search_position: int = -1
|
|
58
|
+
last_search_position: int = -1
|
|
59
|
+
image_number_for_gui: int = 0
|
|
60
|
+
number_of_jobs_per_image_in_gui: int = 0
|
|
61
|
+
result_number: int = 1
|
|
62
|
+
max_threads: int = 1
|
|
63
|
+
directory_for_results: str = "/tmp"
|
|
64
|
+
threshold_for_result_plotting: float = 8.0
|
|
65
|
+
filename_for_gui_result_image: str = "/tmp/gui_result.mrc"
|
|
66
|
+
xyz_coords_filename: str ="/tmp/test.txt"
|
|
67
|
+
read_coordinates: bool = False
|
|
68
|
+
|
|
69
|
+
async def handle_results(reader, writer, logger):
|
|
70
|
+
logger.info("Handling results")
|
|
71
|
+
data = await reader.read(4)
|
|
72
|
+
number_of_bytes = int.from_bytes(data[0:3], byteorder="little")
|
|
73
|
+
results = await reader.read(number_of_bytes)
|
|
74
|
+
return(results)
|
|
75
|
+
|
|
76
|
+
signal_handlers = {
|
|
77
|
+
socket_template_match_result_ready : handle_results
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
def parameters_from_database(database, image_asset_id, template_match_id, **kwargs):
|
|
81
|
+
image_info = get_image_info_from_db(database, image_asset=image_asset_id)
|
|
82
|
+
tm_info = get_tm_info_from_db(database,image_asset_id, template_match_id)
|
|
83
|
+
par = RefineTemplateParameters(input_search_image=image_info["FILENAME"],
|
|
84
|
+
pixel_size=image_info["image_pixel_size"],
|
|
85
|
+
voltate_kV=image_info["VOLTAGE"],
|
|
86
|
+
spherical_aberration_mm=image_info["SPHERICAL_ABERRATION"],
|
|
87
|
+
amplitude_contrast=image_info["AMPLITUDE_CONTRAST"],
|
|
88
|
+
defocus1=image_info["DEFOCUS1"],
|
|
89
|
+
defocus2=image_info["DEFOCUS2"],
|
|
90
|
+
defocus_angle=image_info["DEFOCUS_ANGLE"],
|
|
91
|
+
mip_input_filename=tm_info["MIP_OUTPUT_FILE"],
|
|
92
|
+
scaled_mip_input_filename=tm_info["SCALED_MIP_OUTPUT_FILE"],
|
|
93
|
+
best_defocus_input_filename=tm_info["DEFOCUS_OUTPUT_FILE"],
|
|
94
|
+
best_pixel_size_input_filename=tm_info["PIXEL_SIZE_OUTPUT_FILE"],
|
|
95
|
+
best_psi_input_filename=tm_info["PSI_OUTPUT_FILE"],
|
|
96
|
+
best_theta_input_filename=tm_info["THETA_OUTPUT_FILE"],
|
|
97
|
+
best_phi_input_filename=tm_info["PHI_OUTPUT_FILE"],
|
|
98
|
+
**kwargs)
|
|
99
|
+
return(par)
|
|
100
|
+
|
|
101
|
+
def run(parameters: RefineTemplateParameters):
|
|
102
|
+
byte_result = asyncio.run(cistem_program.run("refine_template", parameters, signal_handlers=signal_handlers))[0]
|
|
103
|
+
struct.unpack_from("<i",byte_result,offset=0)[0]
|
|
104
|
+
peak_numbers = struct.unpack_from("<i",byte_result,offset=4)[0]
|
|
105
|
+
struct.unpack_from("<i",byte_result,offset=8)[0]
|
|
106
|
+
struct.unpack_from("<f",byte_result,offset=12)[0]
|
|
107
|
+
|
|
108
|
+
result_peaks = pd.DataFrame({"peak_number": pd.Series(dtype="int"),
|
|
109
|
+
"x": pd.Series(dtype="float"),
|
|
110
|
+
"y": pd.Series(dtype="float"),
|
|
111
|
+
"psi": pd.Series(dtype="float"),
|
|
112
|
+
"theta": pd.Series(dtype="float"),
|
|
113
|
+
"phi": pd.Series(dtype="float"),
|
|
114
|
+
"defocus": pd.Series(dtype="float"),
|
|
115
|
+
"pixel_size": pd.Series(dtype="float"),
|
|
116
|
+
"peak_value": pd.Series(dtype="float")})
|
|
117
|
+
|
|
118
|
+
for peak_number in range(peak_numbers):
|
|
119
|
+
(x, y, psi, theta, phi, defocus, pixel_size, peak_height) = struct.unpack_from("<ffffffff",byte_result,offset=16+peak_number*32)
|
|
120
|
+
a_series = pd.Series([peak_number, x, y, psi, theta, phi, defocus, pixel_size, peak_height], index = result_peaks.columns)
|
|
121
|
+
result_peaks = result_peaks.append(a_series, ignore_index=True)
|
|
122
|
+
|
|
123
|
+
return(result_peaks)
|
|
124
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Union, List
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from pycistem.programs import cistem_program
|
|
8
|
+
from pycistem.programs._cistem_constants import socket_send_next_job
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class ResampleParameters:
|
|
12
|
+
input_filename: str
|
|
13
|
+
output_filename: str
|
|
14
|
+
is_a_volume: bool = False
|
|
15
|
+
new_x_size: int = 64
|
|
16
|
+
new_y_size: int = 64
|
|
17
|
+
new_z_size: int = 1
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def run(parameters: Union[ResampleParameters,list[ResampleParameters]],**kwargs):
|
|
24
|
+
|
|
25
|
+
if not isinstance(parameters, list):
|
|
26
|
+
parameters = [parameters]
|
|
27
|
+
|
|
28
|
+
asyncio.run(cistem_program.run("resample", parameters, **kwargs))
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
host_gpu_info = {
|
|
3
|
+
"kyiv": 8,
|
|
4
|
+
"warsaw": 8,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
def generate_local_gpu_prefix(num_gpus):
|
|
8
|
+
for gpu in range(num_gpus):
|
|
9
|
+
yield f'CUDA_VISIBLE_DEVICES={gpu} '
|
|
10
|
+
|
|
11
|
+
def generate_gpu_prefix(host_gpu_info):
|
|
12
|
+
for host in host_gpu_info:
|
|
13
|
+
for gpu in range(host_gpu_info[host]):
|
|
14
|
+
yield f'ssh {host} "CUDA_VISIBLE_DEVICES={gpu} '
|
|
15
|
+
|
|
16
|
+
def generate_num_procs(host_gpu_info):
|
|
17
|
+
return sum(host_gpu_info.values())
|