1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from numpy import array, dot, float64, transpose
25
26
27 from lib.structure.geometric import generate_vector_dist, generate_vector_residues
28
29
30 -def diffusion_tensor(mol=None, tensor=None, tensor_diag=None, diff_type=None, rotation=None, axes=None, sim_axes=None, com=None, scale=1.8e-6):
31 """Create the structural representation of the diffusion tensor.
32
33 @keyword mol: The molecule container.
34 @type mol: MolContainer instance
35 @keyword tensor: The diffusion tensor.
36 @type tensor: numpy rank-2, 3D array
37 @keyword tensor_diag: The diagonalised diffusion tensor in tensor frame.
38 @type tensor_diag: numpy rank-2, 3D array
39 @keyword diff_type: The type of diffusion tensor. This can be one of 'sphere', 'oblate', 'prolate', 'ellipsoid'.
40 @type diff_type: str
41 @keyword rotation: The diffusion tensor rotation matrix.
42 @type rotation: numpy rank-2, 3D array
43 @keyword axes: The axis system of the tensor. For the spheroids this is one vector, for the ellipsoid it should be three vectors.
44 @type axes: list of numpy rank-1, 3D arrays
45 @keyword sim_axes: The axis systems of the tensor for each simulation. For the spheroids this is one vector, for the ellipsoid it should be three vectors. The first dimension is the axis type (x, y, or z), the second is the simulation, and the third is the vector.
46 @type sim_axes: None or list of lists of numpy rank-1, 3D arrays
47 @keyword com: The centre of mass of the diffusion structure.
48 @type com: numpy rank-1, 3D array
49 @keyword scale: The scaling factor for the diffusion tensor.
50 @type scale: float
51 """
52
53
54
55
56
57 res_num = 1
58
59
60 mol.atom_add(pdb_record='HETATM', atom_num=1, atom_name='R', res_name='COM', res_num=res_num, pos=com, segment_id=None, element='C')
61
62
63 res_num = res_num + 1
64
65
66
67
68
69
70 print("\nGenerating the geometric object.")
71
72
73 if diff_type == 'prolate':
74
75 z_rot = array([[ 0, -1, 0],
76 [ 1, 0, 0],
77 [ 0, 0, 1]], float64)
78
79
80 rotation = dot(transpose(rotation), z_rot)
81 tensor = dot(z_rot, dot(tensor_diag, transpose(z_rot)))
82 tensor = dot(rotation, dot(tensor, transpose(rotation)))
83
84
85 if diff_type == 'oblate':
86
87 y_rot = array([[ 0, 0, 1],
88 [ 0, 1, 0],
89 [ -1, 0, 0]], float64)
90
91
92 rotation = dot(transpose(rotation), y_rot)
93 tensor = dot(y_rot, dot(tensor_diag, transpose(y_rot)))
94 tensor = dot(rotation, dot(tensor, transpose(rotation)))
95
96
97 generate_vector_dist(mol=mol, res_name='TNS', res_num=res_num, centre=com, R=rotation, warp=tensor, scale=scale, inc=20)
98
99
100 res_num = res_num + 1
101
102
103
104
105
106
107 if diff_type in ['oblate', 'prolate']:
108
109 print("\nGenerating the unique axis of the diffusion tensor.")
110 print(" Scaling factor: " + repr(scale))
111
112
113 res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dpar', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True)
114
115
116
117 if diff_type == 'ellipsoid':
118
119 print("Generating the three axes of the ellipsoid.")
120 print(" Scaling factor: " + repr(scale))
121
122
123 res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dx', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True)
124 res_num = generate_vector_residues(mol=mol, vector=axes[1], atom_name='Dy', res_name_vect='AXS', sim_vectors=sim_axes[1], res_num=res_num, origin=com, scale=scale, neg=True)
125 res_num = generate_vector_residues(mol=mol, vector=axes[2], atom_name='Dz', res_name_vect='AXS', sim_vectors=sim_axes[2], res_num=res_num, origin=com, scale=scale, neg=True)
126