-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_maps.py
More file actions
42 lines (32 loc) · 1.19 KB
/
generate_maps.py
File metadata and controls
42 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gemmi
import numpy as np
import sys
from typing import Tuple, Union
"""
Script to convert a Patterson Map in .map.gz format
to an interpolated 3D numpy array on a 128 A^3 carterian grid
"""
def get_p_map_grid(file_path: str) -> np.array:
return gemmi.read_ccp4_map(file_path).grid
def get_p_map_corrected(
file_path: str,
grid_size: Tuple[float, float, float],
grid_spacing: float) -> Union[np.array, None]:
grid = get_p_map_grid(file_path)
arr = np.zeros(grid_size, dtype=np.float32)
tr = gemmi.Transform()
tr.mat.fromlist([[grid_spacing, 0, 0], [0, grid_spacing, 0], [0, 0, grid_spacing]])
tr.vec.fromlist([-grid_size[0]/2., -grid_size[1]/2., -grid_size[2]/2.])
grid.interpolate_values(arr, tr)
return arr
if __name__ == "__main__":
txt_file = sys.argv[1]
grid_size = (256, 256, 256)
grid_spacing = 0.5
with open(txt_file, "r") as g:
lines = g.readlines()
for line in lines:
file_path = line.split()[-1]
output_path = file_path.replace(".map.gz", ".npy")
arr = get_p_map_corrected(file_path=file_path, grid_size=grid_size, grid_spacing=grid_spacing)
np.save(output_path, arr)