-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchimera_utils.py
112 lines (87 loc) · 3.29 KB
/
chimera_utils.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
#
# Copyright 2016 Holger Ballweg
#
# This file is part of chison.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# chimera -> sonification mapping
import chimera
import numpy as np
import spatialisation as sp
import sound_objects as so
import functools as ft
import datetime
def get_coords(obj):
if hasattr(obj, 'atoms'):
return obj.atoms[0].xformCoord()
else:
return obj.xformCoord()
def ch_get_real_eye():
viewer = chimera.viewer
camera = viewer.camera
real_eye = chimera.Point(*camera.center)
real_eye[2] = camera.eyeZ()
return real_eye
ch_calculate_position = ft.partial(sp.calculate_position, distance_offset=(-24))
def ch_position_sound_object(sobj, real_eye, coords):
dist, az, ele = ch_calculate_position(real_eye, coords)
return so.position_sound_object(sobj, dist, az, ele)
def is_ligand(molecule):
try:
molecule.dockGridScore
return True
except AttributeError:
return False
def save_orig_color():
for molecule in chimera.openModels.list(modelTypes=[chimera.Molecule]):
for a in molecule.atoms:
a.origColor = a.color
if hasattr(molecule, 'residues'):
for r in molecule.residues:
r.origColor = r.ribbonColor
def set_color(obj, color):
if hasattr(obj, 'ribbonColor'):
if not hasattr(obj, 'origColor'):
obj.origColor = obj.ribbonColor
obj.ribbonColor = color
for a in obj.atoms:
if a.display:
set_color(a, color)
elif hasattr(obj, 'color'):
if not hasattr(obj, 'origColor'):
obj.origColor = obj.color
obj.color = color
def restore_color(obj):
if hasattr(obj, 'ribbonColor'):
obj.ribbonColor = obj.origColor
for a in obj.atoms:
if a.display:
restore_color(a)
elif hasattr(obj, 'color'):
obj.color = obj.origColor
else:
print("couldn't restore", obj)
def get_neighbors(obj):
if hasattr(obj, 'bondedResidues'):
return obj.bondedResidues()
else:
return obj.primaryNeighbors()
def redisplay(dialog):
if(chimera.dialogs.find(dialog.name) == None):
chimera.dialogs.register(dialog.name, dialog)
else:
chimera.dialogs.find(dialog.name).destroy()
chimera.dialogs.reregister(dialog.name, dialog)
chimera.dialogs.display(dialog.name)