File: view_utils.py

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (192 lines) | stat: -rw-r--r-- 5,133 bytes parent folder | download | duplicates (4)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from BALL import Atom, Path, PDBAtom, Vector3, atoms, residues
from VIEW import *

__version__ = '1.5'

"""
	I. Convenience access
"""

""" Ia. Widgets """

def getDatasetControl():
	return DatasetControl.getInstance(0)

def getDisplayProperties():
	return DisplayProperties.getInstance(0)

def getGeometricControl():
	return GeometricControl.getInstance(0)

def getLogView():
	return LogView.getInstance(0)

def getMainControl():
	return MainControl.getInstance(0)

def getMolecularControl():
	return MolecularControl.getInstance(0)

def getMolecularStructure():
	return MolecularStructure.getInstance(0)

def getScene():
	return Scene.getInstance(0)


""" Ib. Second-level getters"""

def getForceField():
	return getMolecularStructure().getForceField()

def getMolecularControlSelection():
	return getMainControl().getMolecularControlSelection()

def getOneSystem():
	"""
		Returns the highlighted system. If none or multiple systems are highlighted,
		this function highlights and returns the first system available.
	"""
	s = getMolecularControlSelection()
	if len(s) != 1:
		print("Warning: Excatly one System should be highlighted! Returning first system available.")
		s.append(getSystems()[0])
	s = s[0].getRoot()
	getMolecularControl().highlight([s])
	return s

def getRepresentations():
	return getMainControl().getRepresentationManager().getRepresentations()

def getSelection():
	return getMainControl().getSelection()

def getSystems():
	return getMainControl().getCompositeManager().getComposites()


"""
	II. Main control
"""

def clearSystems():
	[getMainControl().remove(system) for system in getSystems()]

def clearProject():
	getMainControl().clearData()

def clearRepresentations():
	while len(getRepresentations()) > 0:
		getMainControl().remove(getRepresentations()[0])

def hideAllRepresentations():
	for i in range(len(getRepresentations())):
		getRepresentations()[i].setHidden(1)
		getMainControl().update(getRepresentations()[i])

def loadProject(filename):
	loc = Path().find(filename)
	clearProject()
	return getMainControl().loadBALLViewProjectFile(loc)

def openFile(file):
	return getMainControl().openFile(file)

def quickLoad():
	getMainControl().quickLoad()

def quickSave():
	getMainControl().quickSave()

def quitApplication():
	getMainControl().quit()

def setMultithreading(mode):
	getMainControl().setMultithreading(mode)


"""
	III. Misc
"""

def addOptimizedHydrogens():
	getMolecularControl().highlight([getOneSystem()])
	setMultithreading(False)
	getMolecularStructure().addHydrogens()
	getMolecularControl().applySelector("element(H)")
	setMultithreading(True)
	getMolecularStructure().runMinimization(False)

def highlightLigand():
	removeWater()
	l = [r for r in residues(getOneSystem()) if not r.isAminoAcid()]
	getMolecularControl().highlight(l)
	return l

def printAtomTypesForHighlighted():
	print("Atom types for highlighted Items:")
	for r in getMolecularControlSelection():
		if r.__class__ in (Atom, PDBAtom):
			print(str(r.getFullName(Atom.ADD_RESIDUE_ID)) + " : " + str(r.getType()))
		else:
			for a in atoms(r):
				print(a.getFullName(Atom.ADD_RESIDUE_ID) +" : "+str(a.getType()))

def printAtomTypesForLigands():
	highlightLigand()
	printAtomTypesForHighlighted()

def relaxStructure():
	getMolecularControl().highlight([getOneSystem()])
	getScene().optimizeStructure()

def removeWater():
	getMainControl().clearSelection()
	setMultithreading(False)
	if getMolecularControl().applySelector("residue(HOH)") != 0:
		getMolecularControl().highlightSelection()
		getMolecularControl().cut()
	setMultithreading(True)

def selectByExpression(expression):
	getMainControl().clearSelection()
	getMolecularControl().applySelector(expression)

def selectByExpressionAndSetViewPoint(expression, view_point, look_at, look_up):
	setViewPoint(view_point, look_at, look_up)
	selectByExpression(expression)

def setViewPoint(view_point, look_at, look_up):
	getMainControl().clearSelection()
	camera = getScene().getStage().getCamera()
	camera.setViewPoint(Vector3(*[float(e) for e in view_point.split('|')]))
	camera.setLookAtPosition(Vector3(*[float(e) for e in look_at.split('|')]))
	camera.setLookUpVector(Vector3(*[float(e) for e in look_up.split('|')]))
	getScene().setCamera(camera)
	Scene.getInstance(0).applyStereoDefaults()
	getMainControl().update(getRepresentations()[0])

def showCartoonAndLigand():
	s = getOneSystem()
	clearRepresentations()
	highlightLigand()
	getDisplayProperties().selectModel(MODEL_VDW)
	getDisplayProperties().selectColoringMethod(COLORING_ELEMENT)
	getDisplayProperties().apply()
	getMolecularControl().highlight([s])
	getMolecularControl().centerCamera()
	getDisplayProperties().selectModel(MODEL_CARTOON)
	getDisplayProperties().selectColoringMethod(COLORING_RESIDUE_INDEX)
	getDisplayProperties().apply()

def toggleRepresentationByName(name):
	for rep in getRepresentations():
		if rep.getName() == name:
			rep.setHidden(not rep.isHidden())
			getMainControl().update(rep)

def toggleSelectionByExpression(expression):
	if len(getSelection()) == 0:
		getMolecularControl().applySelector(expression)
	else:
		getMainControl().clearSelection()