1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from numpy import array, dot, float64, transpose
24
25
26 from lib.structure.geometric import generate_vector_dist, generate_vector_residues
27
28
29 -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):
30 """Create the structural representation of the diffusion tensor.
31
32 @keyword mol: The molecule container.
33 @type mol: MolContainer instance
34 @keyword tensor: The diffusion tensor.
35 @type tensor: numpy rank-2, 3D array
36 @keyword tensor_diag: The diagonalised diffusion tensor in tensor frame.
37 @type tensor_diag: numpy rank-2, 3D array
38 @keyword diff_type: The type of diffusion tensor. This can be one of 'sphere', 'oblate', 'prolate', 'ellipsoid'.
39 @type diff_type: str
40 @keyword rotation: The diffusion tensor rotation matrix.
41 @type rotation: numpy rank-2, 3D array
42 @keyword axes: The axis system of the tensor. For the spheroids this is one vector, for the ellipsoid it should be three vectors.
43 @type axes: list of numpy rank-1, 3D arrays
44 @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.
45 @type sim_axes: None or list of lists of numpy rank-1, 3D arrays
46 @keyword com: The centre of mass of the diffusion structure.
47 @type com: numpy rank-1, 3D array
48 @keyword scale: The scaling factor for the diffusion tensor.
49 @type scale: float
50 """
51
52
53
54
55
56 res_num = 1
57
58
59 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')
60
61
62 res_num = res_num + 1
63
64
65
66
67
68
69 print("\nGenerating the geometric object.")
70
71
72 if diff_type == 'oblate':
73
74 y_rot = array([[ 0, 0, 1],
75 [ 0, 1, 0],
76 [ -1, 0, 0]], float64)
77
78
79 rotation = dot(transpose(rotation), y_rot)
80 tensor = dot(y_rot, dot(tensor_diag, transpose(y_rot)))
81 tensor = dot(rotation, dot(tensor, transpose(rotation)))
82
83
84 generate_vector_dist(mol=mol, res_name='TNS', res_num=res_num, centre=com, R=rotation, warp=tensor, scale=scale, inc=20)
85
86
87 res_num = res_num + 1
88
89
90
91
92
93
94 if diff_type in ['oblate', 'prolate']:
95
96 print("\nGenerating the unique axis of the diffusion tensor.")
97 print(" Scaling factor: " + repr(scale))
98
99
100 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)
101
102
103
104 if diff_type == 'ellipsoid':
105
106 print("Generating the three axes of the ellipsoid.")
107 print(" Scaling factor: " + repr(scale))
108
109
110 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)
111 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)
112 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)
113