Added design protein 2D
This commit is contained in:
@@ -863,3 +863,39 @@ class EditAMoleculeInput(InputTypeBase):
|
||||
return context
|
||||
|
||||
registry.register(EditAMoleculeInput)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
class DesignProtein2dInput(InputTypeBase):
|
||||
"""
|
||||
An input type for design of a protein in 2D. Integrates with the Protex java applet.
|
||||
|
||||
Example:
|
||||
|
||||
<designprotein2d width="800" hight="500" target_shape="E;NE;NW;W;SW;E;none" />
|
||||
"""
|
||||
|
||||
template = "designprotein2dinput.html"
|
||||
tags = ['designprotein2dinput']
|
||||
|
||||
@classmethod
|
||||
def get_attributes(cls):
|
||||
"""
|
||||
Note: width, hight, and target_shape are required.
|
||||
"""
|
||||
return [Attribute('width'),
|
||||
Attribute('height'),
|
||||
Attribute('target_shape')
|
||||
]
|
||||
|
||||
def _extra_context(self):
|
||||
"""
|
||||
"""
|
||||
context = {
|
||||
'applet_loader': '/static/js/capa/design-protein-2d.js',
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
registry.register(DesignProtein2dInput)
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class LoncapaResponse(object):
|
||||
# problem author can make this span display:inline
|
||||
if self.xml.get('inline',''):
|
||||
tree.set('class','inline')
|
||||
|
||||
|
||||
for item in self.xml:
|
||||
# call provided procedure to do the rendering
|
||||
item_xhtml = renderer(item)
|
||||
@@ -875,7 +875,8 @@ def sympy_check2():
|
||||
|
||||
allowed_inputfields = ['textline', 'textbox', 'crystallography',
|
||||
'chemicalequationinput', 'vsepr_input',
|
||||
'drag_and_drop_input', 'editamoleculeinput']
|
||||
'drag_and_drop_input', 'editamoleculeinput',
|
||||
'designprotein2dinput']
|
||||
|
||||
def setup_response(self):
|
||||
xml = self.xml
|
||||
|
||||
39
common/lib/capa/capa/templates/designprotein2dinput.html
Normal file
39
common/lib/capa/capa/templates/designprotein2dinput.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<section id="designprotein2dinput_${id}" class="designprotein2dinput">
|
||||
<div class="script_placeholder" data-src="${applet_loader}"/>
|
||||
|
||||
% if status == 'unsubmitted':
|
||||
<div class="unanswered" id="status_${id}">
|
||||
% elif status == 'correct':
|
||||
<div class="correct" id="status_${id}">
|
||||
% elif status == 'incorrect':
|
||||
<div class="incorrect" id="status_${id}">
|
||||
% elif status == 'incomplete':
|
||||
<div class="incorrect" id="status_${id}">
|
||||
% endif
|
||||
|
||||
<object type="application/x-java-applet" id="applet_${id}" class="applet" width="${width}" height="${height}">
|
||||
<param name="archive" value="/static/applets/capa/Protex.jar" />
|
||||
<param name="code" value="protex.ProtexApplet.class" />
|
||||
<param name="TARGET_SHAPE" value="${target_shape}" />
|
||||
Applet failed to run. No Java plug-in was found.
|
||||
</object>
|
||||
|
||||
<input type="hidden" name="input_${id}" id="input_${id}" value="${value|h}"/>
|
||||
|
||||
<p class="status">
|
||||
% if status == 'unsubmitted':
|
||||
unanswered
|
||||
% elif status == 'correct':
|
||||
correct
|
||||
% elif status == 'incorrect':
|
||||
incorrect
|
||||
% elif status == 'incomplete':
|
||||
incomplete
|
||||
% endif
|
||||
</p>
|
||||
|
||||
<p id="answer_${id}" class="answer"></p>
|
||||
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
|
||||
</div>
|
||||
% endif
|
||||
</section>
|
||||
BIN
common/static/applets/capa/Protex.jar
Normal file
BIN
common/static/applets/capa/Protex.jar
Normal file
Binary file not shown.
27
common/static/js/capa/design-protein-2d.js
Normal file
27
common/static/js/capa/design-protein-2d.js
Normal file
@@ -0,0 +1,27 @@
|
||||
(function () {
|
||||
var timeout = 1000;
|
||||
|
||||
function initializeApplet(applet) {
|
||||
console.log("Initializing " + applet);
|
||||
waitForApplet(applet);
|
||||
}
|
||||
|
||||
function waitForApplet(applet) {
|
||||
if (applet.isActive && applet.isActive()) {
|
||||
console.log("Applet is ready.");
|
||||
var answerStr = applet.checkAnswer();
|
||||
console.log(answerStr);
|
||||
var input = $('.designprotein2dinput input');
|
||||
console.log(input);
|
||||
input.val(answerStr);
|
||||
} else if (timeout > 30 * 1000) {
|
||||
console.error("Applet did not load on time.");
|
||||
} else {
|
||||
console.log("Waiting for applet...");
|
||||
setTimeout(function() { waitForApplet(applet); }, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
var applets = $('.designprotein2dinput object');
|
||||
applets.each(function(i, el) { initializeApplet(el); });
|
||||
}).call(this);
|
||||
Reference in New Issue
Block a user