Esempio n. 1
0
def test_06_MSMS():
    # test the MSMS node
    net = ed.currentNetwork
    net.runOnNewData.value = True    
    node1 = ReadMolecule(library=molkitlib)
    net.addNode(node1, 20, 20)
    node1.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"))
    # assign radii
    node2 = AssignRadii(library=molkitlib)
    net.addNode(node2, 275, 62)
    net.connectNodes(node1, node2, "MolSets", "molecules")
    node2.toggleNodeExpand_cb()
    # select nodes
    node3 = NodeSelector(library=molkitlib)
    net.addNode(node3, 14, 153)
    net.connectNodes(node2, node3, "molecules", "nodes")
    node3.toggleNodeExpand_cb()
    # msms
    node4 = AtomsAsMSMS(library=molkitlib)
    net.addNode(node4, 263, 267)
    net.connectNodes(node3, node4, "nodes", "atoms")
    net.connectNodes(node2, node4, "radii", "radii")
    pause()
    # check data
    from mslib import MSMS
    assert isinstance(node4.outputPorts[0].data, MSMS),\
           "Expected %s, got %s"%(MSMS, node4.outputPorts[0].data.__class__)
    assert len(node4.outputPorts[0].data.coords) == 327,\
           "Expected 327, got %s"%len(node4.outputPorts[0].data.coords)
    # just for the fun of it, click the united radii checkbutton a couple times
    node2.inputPorts[1].widget.set(1)
    node2.inputPorts[1].widget.set(0)
    node2.inputPorts[1].widget.set(1)
    node2.inputPorts[1].widget.set(0)
Esempio n. 2
0
def test_06_MSMS():
    # test the MSMS node
    net = ed.currentNetwork
    net.runOnNewData.value = True
    node1 = ReadMolecule(library=molkitlib)
    net.addNode(node1, 20, 20)
    node1.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"))
    # assign radii
    node2 = AssignRadii(library=molkitlib)
    net.addNode(node2, 275, 62)
    net.connectNodes(node1, node2, "MolSets", "molecules")
    node2.toggleNodeExpand_cb()
    # select nodes
    node3 = NodeSelector(library=molkitlib)
    net.addNode(node3, 14, 153)
    net.connectNodes(node2, node3, "molecules", "nodes")
    node3.toggleNodeExpand_cb()
    # msms
    node4 = AtomsAsMSMS(library=molkitlib)
    net.addNode(node4, 263, 267)
    net.connectNodes(node3, node4, "nodes", "atoms")
    net.connectNodes(node2, node4, "radii", "radii")
    pause()
    # check data
    from mslib import MSMS
    assert isinstance(node4.outputPorts[0].data, MSMS),\
           "Expected %s, got %s"%(MSMS, node4.outputPorts[0].data.__class__)
    assert len(node4.outputPorts[0].data.coords) == 327,\
           "Expected 327, got %s"%len(node4.outputPorts[0].data.coords)
    # just for the fun of it, click the united radii checkbutton a couple times
    node2.inputPorts[1].widget.set(1)
    node2.inputPorts[1].widget.set(0)
    node2.inputPorts[1].widget.set(1)
    node2.inputPorts[1].widget.set(0)
Esempio n. 3
0
def test_05_AtomsProperty():
    # test the Extract Atoms property node
    net = ed.currentNetwork
    net.runOnNewData.value = True
    node1 = ReadMolecule(library=molkitlib)
    net.addNode(node1, 20, 20)
    node1.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"))
    node2 = NodeSelector(library=molkitlib)
    net.addNode(node2, 30, 100)
    net.connectNodes(node1, node2, "MolSets", "nodes")
    node3 = AtomsProperty(library=molkitlib)
    net.addNode(node3, 90, 170)
    net.connectNodes(node2, node3, "nodes", "atoms")
    node3.toggleNodeExpand_cb()
    pause()
    # define a couple of attributes we want to access
    # FIXME: ATTRIBUTE "radius" is not working!!??
    attrs = [
        "_uniqIndex", "atomicNumber", "bondOrderRadius", "covalentRadius",
        "element", "name", "number", "organic", "segID", "temperatureFactor",
        "vdwRadius"
    ]
    for a in attrs:
        node3.inputPorts[1].widget.set(a)
        assert len(node3.outputPorts[0].data) == 327,\
               "Expected 327, got %s"%len(node3.outputPorts[0].data)
Esempio n. 4
0
def test_02_NodeSelector():
    # test the select 'node' node
    net = ed.currentNetwork
    net.runOnNewData.value = True
    node1 = ReadMolecule(library=molkitlib)
    net.addNode(node1, 20, 20)
    node1.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"))
    node2 = NodeSelector(library=molkitlib)
    net.addNode(node2, 30, 100)
    net.connectNodes(node1, node2, "MolSets", "nodes")
    node2.toggleNodeExpand_cb()
    pause()
    # because we run(), upon connecting we pass the data and the output of
    # node2 should have data
    # default node output is AtomSet
    from MolKit.molecule import AtomSet
    data = node2.outputPorts[0].data
    assert isinstance(
        data, AtomSet), "Expected %s, got %s" % (AtomSet, data.__class__)
    # switch to ResidueSet
    from MolKit.protein import ResidueSet
    node2.inputPorts[1].widget.set("Residue")
    data = node2.outputPorts[0].data
    assert isinstance(
        data, ResidueSet), "Expected %s, got %s" % (ResidueSet, data.__class__)
    # switch to Chain
    from MolKit.protein import ChainSet
    node2.inputPorts[1].widget.set("Chain")
    data = node2.outputPorts[0].data
    assert isinstance(
        data, ChainSet), "Expected %s, got %s" % (ChainSet, data.__class__)
    # switch to Molecule
    from MolKit.molecule import MoleculeSet
    node2.inputPorts[1].widget.set("Molecule")
    data = node2.outputPorts[0].data
    assert isinstance(
        data,
        MoleculeSet), "Expected %s, got %s" % (MoleculeSet, data.__class__)
Esempio n. 5
0
def test_02_NodeSelector():
    # test the select 'node' node
    net = ed.currentNetwork
    net.runOnNewData.value = True    
    node1 = ReadMolecule(library=molkitlib)
    net.addNode(node1, 20, 20)
    node1.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"))
    node2 = NodeSelector(library=molkitlib)
    net.addNode(node2, 30, 100)
    net.connectNodes(node1, node2, "MolSets", "nodes")
    node2.toggleNodeExpand_cb()
    pause()
    # because we run(), upon connecting we pass the data and the output of
    # node2 should have data
    # default node output is AtomSet
    from MolKit.molecule import AtomSet
    data = node2.outputPorts[0].data
    assert isinstance(data, AtomSet), "Expected %s, got %s"%(
        AtomSet, data.__class__)
    # switch to ResidueSet
    from MolKit.protein import ResidueSet
    node2.inputPorts[1].widget.set("Residue")
    data = node2.outputPorts[0].data
    assert isinstance(data, ResidueSet), "Expected %s, got %s"%(
        ResidueSet, data.__class__)
    # switch to Chain
    from MolKit.protein import ChainSet
    node2.inputPorts[1].widget.set("Chain")
    data = node2.outputPorts[0].data
    assert isinstance(data, ChainSet), "Expected %s, got %s"%(
        ChainSet, data.__class__)
    # switch to Molecule
    from MolKit.molecule import MoleculeSet
    node2.inputPorts[1].widget.set("Molecule")
    data = node2.outputPorts[0].data
    assert isinstance(data, MoleculeSet), "Expected %s, got %s"%(
        MoleculeSet, data.__class__)
Esempio n. 6
0
def test_07_MSMSWithAtomSubset():
    # test if we can pass an atom set (C,CA,N) to compute an MSMS
    masterNet = ed.currentNetwork
    ## saving node Read Molecule ##
    node0 = ReadMolecule(library=molkitlib)
    masterNet.addNode(node0, 20, 20)
    node0.inputPorts[0].widget.set(os.path.abspath("1crn.pdb"),
                                   0)  # do not run yet
    ## saving node MSMS ##
    node2 = AtomsAsMSMS(library=molkitlib)
    masterNet.addNode(node2, 250, 275)
    ## saving node Select Nodes ##
    node4 = NodeSelector(library=molkitlib)
    masterNet.addNode(node4, 14, 153)
    node4.inputPorts[2].widget.set("C,CA,N")
    apply(node4.configure, (), {'expanded': True})
    ## saving node Assign Radii ##
    node5 = AssignRadii(library=molkitlib)
    masterNet.addNode(node5, 275, 62)
    apply(node5.configure, (), {'expanded': True})
    ## saving node Extract Atom Property ##
    node7 = AtomsProperty(library=molkitlib)
    masterNet.addNode(node7, 302, 169)
    node7.inputPorts[1].widget.set("radius")
    apply(node7.configure, (), {'expanded': True})
    ## saving connections for network Network 0 ##
    masterNet.connectNodes(node0, node5, "MolSets", "molecules")
    masterNet.connectNodes(node5, node4, "molecules", "nodes")
    masterNet.connectNodes(node4, node2, "nodes", "atoms")
    masterNet.connectNodes(node4, node7, "nodes", "atoms")
    masterNet.connectNodes(node7, node2, "propertyValues", "radii")
    pause()
    masterNet.run()
    # check if the data is correct
    # (compare to above: the entire AtomSet would be 237)
    assert node2.outputPorts[0].data is not None,\
           "Expected data, got %s"%node2.outputPorts[0].data
    assert len(node2.outputPorts[0].data.coords) == 138,\
           "Expected 128, got %s"%len(node2.outputPorts[0].data.coords)
Esempio n. 7
0
    ## saving node Assign Radii ##
    from MolKit.VisionInterface.MolKitNodes import AssignRadii
    node1 = AssignRadii(constrkw={}, name='Assign Radii', library=molkitlib)
    masterNet.addNode(node1, 86, 114)
    widget = node1.inputPorts[1].widget
    widget.set(0, 0)
except:
    print "WARNING: failed to restore node AssignRadii called Assign Radii in network masterNet"
    print_exc()
    node1 = None
try:

    ## saving node Select Nodes ##
    from MolKit.VisionInterface.MolKitNodes import NodeSelector
    node2 = NodeSelector(constrkw={}, name='Select Nodes', library=molkitlib)
    masterNet.addNode(node2, 89, 177)
    widget = node2.inputPorts[1].widget
    widget.set("Atom", 0)
    widget = node2.inputPorts[2].widget
    widget.set("", 0)
except:
    print "WARNING: failed to restore node NodeSelector called Select Nodes in network masterNet"
    print_exc()
    node2 = None
try:

    ## saving node CPK ##
    from MolKit.VisionInterface.MolKitNodes import AtomsAsCPK
    node3 = AtomsAsCPK(constrkw={}, name='CPK', library=molkitlib)
    masterNet.addNode(node3, 85, 250)
Esempio n. 8
0
    def afterAddingToNetwork(self):
        from NetworkEditor.macros import MacroNode
        MacroNode.afterAddingToNetwork(self)
        ## loading libraries ##
        from MolKit.VisionInterface.MolKitNodes import molkitlib
        from DejaVu.VisionInterface.DejaVuNodes import vizlib
        from Vision.StandardNodes import stdlib
        ## building macro network ##
        WebMSMS = self
        from traceback import print_exc

        ## loading libraries ##
        from MolKit.VisionInterface.MolKitNodes import molkitlib
        self.macroNetwork.getEditor().addLibraryInstance(molkitlib,"MolKit.VisionInterface.MolKitNodes", "molkitlib")

        from DejaVu.VisionInterface.DejaVuNodes import vizlib
        self.macroNetwork.getEditor().addLibraryInstance(vizlib,"DejaVu.VisionInterface.DejaVuNodes", "vizlib")

        from Vision.StandardNodes import stdlib
        self.macroNetwork.getEditor().addLibraryInstance(stdlib,"Vision.StandardNodes", "stdlib")

        try:

            ## saving node input Ports ##
            input_Ports = self.macroNetwork.ipNode
            input_Ports.move(13, 4)
        except:
            print "WARNING: failed to restore MacroInputNode named input Ports in network self.macroNetwork"
            print_exc()
            input_Ports=None
        try:

            ## saving node output Ports ##
            output_Ports = self.macroNetwork.opNode
            output_Ports.move(256, 220)
        except:
            print "WARNING: failed to restore MacroOutputNode named output Ports in network self.macroNetwork"
            print_exc()
            output_Ports=None
        try:

            ## saving node Assign Radii ##
            from MolKit.VisionInterface.MolKitNodes import AssignRadii
            Assign_Radii = AssignRadii(constrkw = {}, name='Assign Radii', library=molkitlib)
            self.macroNetwork.addNode(Assign_Radii,30,68)
            apply(Assign_Radii.getInputPortByName('molecules').configure, (), {'color': '#c64e70', 'cast': True, 'shape': 'oval'})
            apply(Assign_Radii.getInputPortByName('united').configure, (), {'color': 'yellow', 'cast': True, 'shape': 'circle'})
            apply(Assign_Radii.getOutputPortByName('molecules').configure, (), {'color': '#c64e70', 'shape': 'oval'})
            apply(Assign_Radii.getOutputPortByName('radii').configure, (), {'color': 'cyan', 'shape': 'oval'})
        except:
            print "WARNING: failed to restore AssignRadii named Assign Radii in network self.macroNetwork"
            print_exc()
            Assign_Radii=None
        try:

            ## saving node Select Nodes ##
            from MolKit.VisionInterface.MolKitNodes import NodeSelector
            Select_Nodes = NodeSelector(constrkw = {}, name='Select Nodes', library=molkitlib)
            self.macroNetwork.addNode(Select_Nodes,29,135)
            apply(Select_Nodes.getInputPortByName('nodes').configure, (), {'color': '#c64e70', 'cast': True, 'shape': 'oval'})
            apply(Select_Nodes.getInputPortByName('nodeType').configure, (), {'color': 'white', 'cast': True, 'shape': 'oval'})
            apply(Select_Nodes.getInputPortByName('selectionString').configure, (), {'color': 'white', 'cast': True, 'shape': 'oval'})
            apply(Select_Nodes.getOutputPortByName('nodes').configure, (), {'color': '#fe92a0', 'shape': 'oval'})
            Select_Nodes.getInputPortByName("selectionString").widget.set(".*")
        except:
            print "WARNING: failed to restore NodeSelector named Select Nodes in network self.macroNetwork"
            print_exc()
            Select_Nodes=None
        try:

            ## saving node Get xyzr ##
            from Vision.StandardNodes import Generic
            Get_xyzr = Generic(constrkw = {}, name='Get xyzr', library=stdlib)
            self.macroNetwork.addNode(Get_xyzr,30,194)
            apply(Get_xyzr.addInputPort, (), {'name': 'atoms', 'cast': True, 'datatype': 'AtomSet', 'height': 8, 'width': 12, 'shape': 'oval', 'color': '#fe92a0'})
            apply(Get_xyzr.addOutputPort, (), {'name': 'output', 'datatype': 'string', 'height': 12, 'width': 12, 'shape': 'oval', 'color': 'white'})
            code = """def doit(self, atoms):
    lines = ''
    for atom in atoms:
        lines += str(atom.coords[0]) + ' ' + str(atom.coords[1]) + ' ' + str(atom.coords[2]) + ' '+ str(atom.radius)
        lines += "\\n"
    self.outputData(output=lines)
"""

            Get_xyzr.configure(function=code)
        except:
            print "WARNING: failed to restore Generic named Get xyzr in network self.macroNetwork"
            print_exc()
            Get_xyzr=None
        try:

            ## saving node IndexedPolygons ##
            from DejaVu.VisionInterface.GeometryNode import IndexedPolygonsNE
            IndexedPolygons = IndexedPolygonsNE(constrkw = {}, name='IndexedPolygons', library=vizlib)
            self.macroNetwork.addNode(IndexedPolygons,273,147)
            apply(IndexedPolygons.getInputPortByName('coords').configure, (), {'color': 'purple', 'cast': True, 'shape': 'circle'})
            apply(IndexedPolygons.getInputPortByName('indices').configure, (), {'color': 'yellow', 'cast': True, 'shape': 'circle'})
            apply(IndexedPolygons.getInputPortByName('vnormals').configure, (), {'cast': True, 'shape': 'circle'})
            apply(IndexedPolygons.getInputPortByName('colors').configure, (), {'cast': True, 'shape': 'circle'})
            apply(IndexedPolygons.getInputPortByName('name').configure, (), {'color': 'white', 'cast': True, 'shape': 'oval'})
            apply(IndexedPolygons.getInputPortByName('instanceMatrices').configure, (), {'cast': True})
            apply(IndexedPolygons.getInputPortByName('geomOptions').configure, (), {'color': 'cyan', 'cast': True, 'shape': 'oval'})
            apply(IndexedPolygons.getInputPortByName('parent').configure, (), {'color': 'red', 'cast': True, 'shape': 'rect'})
            apply(IndexedPolygons.getOutputPortByName('indexedPolygons').configure, (), {'color': 'red', 'shape': 'rect'})
            apply(IndexedPolygons.getOutputPortByName('allGeometries').configure, (), {'color': 'red', 'shape': 'rect'})
        except:
            print "WARNING: failed to restore IndexedPolygonsNE named IndexedPolygons in network self.macroNetwork"
            print_exc()
            IndexedPolygons=None
        try:

            ## saving node MSMS WS ##
            from Vision.StandardNodes import Generic
            MSMS_WS = Generic(constrkw = {}, name='MSMS WS', library=stdlib)            

            self.macroNetwork.addNode(MSMS_WS,273,37)
            apply(MSMS_WS.addInputPort, (), {'name': 'input_str', 'cast': True, 
                   'datatype': 'string', 'height': 12, 'width': 12, 'shape': 'oval', 'color': 'white'})
            apply(MSMS_WS.addInputPort, (), {'name': 'density', 'datatype': 'float', 'required':False})
            apply(MSMS_WS.getInputPortByName('density').createWidget, (), 
                   {'descr':{'initialValue': 1.0, 'increment':0.1, 'type':'float', 
                     'master': 'ParamPanel', 'oneTurn':10, 'min':1.0, 'labelCfg': {'text': 'density'}, 'class': 'NEDial'}})
            apply(MSMS_WS.addInputPort, (), {'name': 'probe_radius', 'datatype': 'float', 'required':False})
            apply(MSMS_WS.getInputPortByName('probe_radius').createWidget, (), 
                   {'descr':{'initialValue': 1.5, 'increment':0.1, 'type':'float', 
                     'master': 'ParamPanel', 'oneTurn':10, 'min':0.5, 'labelCfg': {'text': 'probe radius'}, 'class': 'NEDial'}})
            apply(MSMS_WS.addInputPort, (), {'name': 'allComp', 'datatype': 'int', 'required':False})
            apply(MSMS_WS.getInputPortByName('allComp').createWidget, (), 
                   {'descr':{'initialValue': 0, 'master': 'ParamPanel', 'labelCfg': 
                       {'text': 'all components'}, 'class': 'NECheckButton'}})
            apply(MSMS_WS.addInputPort, (), {'name': 'getfile', 'datatype': 'boolean'})
            apply(MSMS_WS.getInputPortByName('getfile').createWidget, (), 
                   {'descr':{'master': 'ParamPanel', 'labelCfg': {'text': 'upload output'}, 'class': 'NECheckButton', 'initialValue':True }})


            apply(MSMS_WS.addOutputPort, (), {'name': 'vertices', 'datatype': 'coordinates3D', 'height': 8, 'width': 12, 'shape': 'rect', 'color': 'green'})
            apply(MSMS_WS.addOutputPort, (), {'name': 'indices', 'datatype': 'faceIndices', 'height': 8, 'width': 12, 'shape': 'rect', 'color': 'purple'})
            apply(MSMS_WS.addOutputPort, (), {'name': 'vnormals', 'datatype': 'normals3D', 'height': 8, 'width': 12, 'shape': 'rect', 'color': 'blue'})
            MSMS_WS.host = self.host
            MSMS_WS.opal_service = self.opal_service
            
            code = """def doit(self, input_str, probe_radius, density, allComp, getfile):
    self.opal_service.inputFile.Set_name('msms.xyzr')
    self.opal_service.inputFile.Set_contents(input_str)
    options = '-if msms.xyzr -of ws_out '
    options += '-probe_radius ' + str(probe_radius)
    options += ' -density ' + str(density)
    if allComp:
        options += ' -all_components'
    self.opal_service.req._argList = options
    inputFiles = []
    inputFiles.append(self.opal_service.inputFile)
    self.opal_service.req._inputFile = inputFiles
    resp = self.opal_service.run('msmsServicePort')
    if resp:
        for files in resp._outputFile:
            if files._url.split('/')[-1] == 'ws_out.face':
                face_file = files._url
            if files._url.split('/')[-1] == 'ws_out.vert':
                vert_file = files._url
        if getfile:           
            from Pmv.msmsParser import MSMSParser
            msmsParser = MSMSParser()
            import urllib
            opener = urllib.FancyURLopener({})
            in_file = opener.open(face_file)
            msmsParser.getFaces(in_file.readlines())
            in_file = opener.open(vert_file)
            msmsParser.getVert(in_file.readlines())
            self.outputData(vertices = msmsParser.vertices, indices = msmsParser.faces,
                          vnormals = msmsParser.normals)
        else:
            self.outputData(vertices = vert_file, indices = face_file,
                          vnormals = None)
"""
            MSMS_WS.configure(function=code)
        except:
            print "WARNING: failed to restore Generic named MSMS WS in network self.macroNetwork"
            print_exc()
            MSMS_WS=None
        self.macroNetwork.freeze()

        ## saving connections for network WebMSMS ##
        if Assign_Radii is not None and Select_Nodes is not None:
            self.macroNetwork.connectNodes(
                Assign_Radii, Select_Nodes, "molecules", "nodes", blocking=True)
        if Select_Nodes is not None and Get_xyzr is not None:
            self.macroNetwork.connectNodes(
                Select_Nodes, Get_xyzr, "nodes", "atoms", blocking=True)
        if Get_xyzr is not None and MSMS_WS is not None:
            self.macroNetwork.connectNodes(
                Get_xyzr, MSMS_WS, "output", "input_str", blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(
                MSMS_WS, IndexedPolygons, "vertices", "coords", blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(
                MSMS_WS, IndexedPolygons, "indices", "indices", blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(
                MSMS_WS, IndexedPolygons, "vnormals", "vnormals", blocking=True)
        output_Ports = self.macroNetwork.opNode
        if IndexedPolygons is not None and output_Ports is not None:
            self.macroNetwork.connectNodes(
                IndexedPolygons, output_Ports, "indexedPolygons", "new", blocking=True)
        input_Ports = self.macroNetwork.ipNode
        if input_Ports is not None and Assign_Radii is not None:
            self.macroNetwork.connectNodes(
                input_Ports, Assign_Radii, "new", "molecules", blocking=True)
        self.macroNetwork.unfreeze()

        WebMSMS.shrink()

        ## reset modifications ##
        WebMSMS.resetTags()
        WebMSMS.buildOriginalList()
Esempio n. 9
0
from MolKit.VisionInterface.MolKitNodes import molkitlib
masterNet.getEditor().addLibraryInstance(molkitlib,
                                         "MolKit.VisionInterface.MolKitNodes",
                                         "molkitlib")

from DejaVu.VisionInterface.DejaVuNodes import vizlib
masterNet.getEditor().addLibraryInstance(vizlib,
                                         "DejaVu.VisionInterface.DejaVuNodes",
                                         "vizlib")

try:
    ## saving node Select MolFrag ##
    from MolKit.VisionInterface.MolKitNodes import NodeSelector
    Select_MolFrag_0 = NodeSelector(constrkw={},
                                    name='Select MolFrag',
                                    library=molkitlib)
    masterNet.addNode(Select_MolFrag_0, 201, 156)
    Select_MolFrag_0.inputPortByName['selectionString'].widget.set("CA",
                                                                   run=False)
except:
    print "WARNING: failed to restore NodeSelector named Select MolFrag in network masterNet"
    print_exc()
    Select_MolFrag_0 = None

try:
    ## saving node Extract Atom Property ##
    from MolKit.VisionInterface.MolKitNodes import AtomsProperty
    Extract_Atom_Property_1 = AtomsProperty(constrkw={},
                                            name='Extract Atom Property',
                                            library=molkitlib)
Esempio n. 10
0
    def afterAddingToNetwork(self):
        from NetworkEditor.macros import MacroNode
        MacroNode.afterAddingToNetwork(self)
        ## loading libraries ##
        from MolKit.VisionInterface.MolKitNodes import molkitlib
        from DejaVu.VisionInterface.DejaVuNodes import vizlib
        from Vision.StandardNodes import stdlib
        ## building macro network ##
        WebMSMS = self
        from traceback import print_exc

        ## loading libraries ##
        from MolKit.VisionInterface.MolKitNodes import molkitlib
        self.macroNetwork.getEditor().addLibraryInstance(
            molkitlib, "MolKit.VisionInterface.MolKitNodes", "molkitlib")

        from DejaVu.VisionInterface.DejaVuNodes import vizlib
        self.macroNetwork.getEditor().addLibraryInstance(
            vizlib, "DejaVu.VisionInterface.DejaVuNodes", "vizlib")

        from Vision.StandardNodes import stdlib
        self.macroNetwork.getEditor().addLibraryInstance(
            stdlib, "Vision.StandardNodes", "stdlib")

        try:

            ## saving node input Ports ##
            input_Ports = self.macroNetwork.ipNode
            input_Ports.move(13, 4)
        except:
            print "WARNING: failed to restore MacroInputNode named input Ports in network self.macroNetwork"
            print_exc()
            input_Ports = None
        try:

            ## saving node output Ports ##
            output_Ports = self.macroNetwork.opNode
            output_Ports.move(256, 220)
        except:
            print "WARNING: failed to restore MacroOutputNode named output Ports in network self.macroNetwork"
            print_exc()
            output_Ports = None
        try:

            ## saving node Assign Radii ##
            from MolKit.VisionInterface.MolKitNodes import AssignRadii
            Assign_Radii = AssignRadii(constrkw={},
                                       name='Assign Radii',
                                       library=molkitlib)
            self.macroNetwork.addNode(Assign_Radii, 30, 68)
            apply(
                Assign_Radii.getInputPortByName('molecules').configure, (), {
                    'color': '#c64e70',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                Assign_Radii.getInputPortByName('united').configure, (), {
                    'color': 'yellow',
                    'cast': True,
                    'shape': 'circle'
                })
            apply(
                Assign_Radii.getOutputPortByName('molecules').configure, (), {
                    'color': '#c64e70',
                    'shape': 'oval'
                })
            apply(
                Assign_Radii.getOutputPortByName('radii').configure, (), {
                    'color': 'cyan',
                    'shape': 'oval'
                })
        except:
            print "WARNING: failed to restore AssignRadii named Assign Radii in network self.macroNetwork"
            print_exc()
            Assign_Radii = None
        try:

            ## saving node Select Nodes ##
            from MolKit.VisionInterface.MolKitNodes import NodeSelector
            Select_Nodes = NodeSelector(constrkw={},
                                        name='Select Nodes',
                                        library=molkitlib)
            self.macroNetwork.addNode(Select_Nodes, 29, 135)
            apply(
                Select_Nodes.getInputPortByName('nodes').configure, (), {
                    'color': '#c64e70',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                Select_Nodes.getInputPortByName('nodeType').configure, (), {
                    'color': 'white',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                Select_Nodes.getInputPortByName('selectionString').configure,
                (), {
                    'color': 'white',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                Select_Nodes.getOutputPortByName('nodes').configure, (), {
                    'color': '#fe92a0',
                    'shape': 'oval'
                })
            Select_Nodes.getInputPortByName("selectionString").widget.set(".*")
        except:
            print "WARNING: failed to restore NodeSelector named Select Nodes in network self.macroNetwork"
            print_exc()
            Select_Nodes = None
        try:

            ## saving node Get xyzr ##
            from Vision.StandardNodes import Generic
            Get_xyzr = Generic(constrkw={}, name='Get xyzr', library=stdlib)
            self.macroNetwork.addNode(Get_xyzr, 30, 194)
            apply(
                Get_xyzr.addInputPort, (), {
                    'name': 'atoms',
                    'cast': True,
                    'datatype': 'AtomSet',
                    'height': 8,
                    'width': 12,
                    'shape': 'oval',
                    'color': '#fe92a0'
                })
            apply(
                Get_xyzr.addOutputPort, (), {
                    'name': 'output',
                    'datatype': 'string',
                    'height': 12,
                    'width': 12,
                    'shape': 'oval',
                    'color': 'white'
                })
            code = """def doit(self, atoms):
    lines = ''
    for atom in atoms:
        lines += str(atom.coords[0]) + ' ' + str(atom.coords[1]) + ' ' + str(atom.coords[2]) + ' '+ str(atom.radius)
        lines += "\\n"
    self.outputData(output=lines)
"""

            Get_xyzr.configure(function=code)
        except:
            print "WARNING: failed to restore Generic named Get xyzr in network self.macroNetwork"
            print_exc()
            Get_xyzr = None
        try:

            ## saving node IndexedPolygons ##
            from DejaVu.VisionInterface.GeometryNode import IndexedPolygonsNE
            IndexedPolygons = IndexedPolygonsNE(constrkw={},
                                                name='IndexedPolygons',
                                                library=vizlib)
            self.macroNetwork.addNode(IndexedPolygons, 273, 147)
            apply(
                IndexedPolygons.getInputPortByName('coords').configure, (), {
                    'color': 'purple',
                    'cast': True,
                    'shape': 'circle'
                })
            apply(
                IndexedPolygons.getInputPortByName('indices').configure, (), {
                    'color': 'yellow',
                    'cast': True,
                    'shape': 'circle'
                })
            apply(
                IndexedPolygons.getInputPortByName('vnormals').configure, (), {
                    'cast': True,
                    'shape': 'circle'
                })
            apply(
                IndexedPolygons.getInputPortByName('colors').configure, (), {
                    'cast': True,
                    'shape': 'circle'
                })
            apply(
                IndexedPolygons.getInputPortByName('name').configure, (), {
                    'color': 'white',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                IndexedPolygons.getInputPortByName(
                    'instanceMatrices').configure, (), {'cast': True})
            apply(
                IndexedPolygons.getInputPortByName('geomOptions').configure,
                (), {
                    'color': 'cyan',
                    'cast': True,
                    'shape': 'oval'
                })
            apply(
                IndexedPolygons.getInputPortByName('parent').configure, (), {
                    'color': 'red',
                    'cast': True,
                    'shape': 'rect'
                })
            apply(
                IndexedPolygons.getOutputPortByName(
                    'indexedPolygons').configure, (), {
                        'color': 'red',
                        'shape': 'rect'
                    })
            apply(
                IndexedPolygons.getOutputPortByName('allGeometries').configure,
                (), {
                    'color': 'red',
                    'shape': 'rect'
                })
        except:
            print "WARNING: failed to restore IndexedPolygonsNE named IndexedPolygons in network self.macroNetwork"
            print_exc()
            IndexedPolygons = None
        try:

            ## saving node MSMS WS ##
            from Vision.StandardNodes import Generic
            MSMS_WS = Generic(constrkw={}, name='MSMS WS', library=stdlib)

            self.macroNetwork.addNode(MSMS_WS, 273, 37)
            apply(
                MSMS_WS.addInputPort, (), {
                    'name': 'input_str',
                    'cast': True,
                    'datatype': 'string',
                    'height': 12,
                    'width': 12,
                    'shape': 'oval',
                    'color': 'white'
                })
            apply(MSMS_WS.addInputPort, (), {
                'name': 'density',
                'datatype': 'float',
                'required': False
            })
            apply(
                MSMS_WS.getInputPortByName('density').createWidget, (), {
                    'descr': {
                        'initialValue': 1.0,
                        'increment': 0.1,
                        'type': 'float',
                        'master': 'ParamPanel',
                        'oneTurn': 10,
                        'min': 1.0,
                        'labelCfg': {
                            'text': 'density'
                        },
                        'class': 'NEDial'
                    }
                })
            apply(MSMS_WS.addInputPort, (), {
                'name': 'probe_radius',
                'datatype': 'float',
                'required': False
            })
            apply(
                MSMS_WS.getInputPortByName('probe_radius').createWidget, (), {
                    'descr': {
                        'initialValue': 1.5,
                        'increment': 0.1,
                        'type': 'float',
                        'master': 'ParamPanel',
                        'oneTurn': 10,
                        'min': 0.5,
                        'labelCfg': {
                            'text': 'probe radius'
                        },
                        'class': 'NEDial'
                    }
                })
            apply(MSMS_WS.addInputPort, (), {
                'name': 'allComp',
                'datatype': 'int',
                'required': False
            })
            apply(
                MSMS_WS.getInputPortByName('allComp').createWidget, (), {
                    'descr': {
                        'initialValue': 0,
                        'master': 'ParamPanel',
                        'labelCfg': {
                            'text': 'all components'
                        },
                        'class': 'NECheckButton'
                    }
                })
            apply(MSMS_WS.addInputPort, (), {
                'name': 'getfile',
                'datatype': 'boolean'
            })
            apply(
                MSMS_WS.getInputPortByName('getfile').createWidget, (), {
                    'descr': {
                        'master': 'ParamPanel',
                        'labelCfg': {
                            'text': 'upload output'
                        },
                        'class': 'NECheckButton',
                        'initialValue': True
                    }
                })

            apply(
                MSMS_WS.addOutputPort, (), {
                    'name': 'vertices',
                    'datatype': 'coordinates3D',
                    'height': 8,
                    'width': 12,
                    'shape': 'rect',
                    'color': 'green'
                })
            apply(
                MSMS_WS.addOutputPort, (), {
                    'name': 'indices',
                    'datatype': 'faceIndices',
                    'height': 8,
                    'width': 12,
                    'shape': 'rect',
                    'color': 'purple'
                })
            apply(
                MSMS_WS.addOutputPort, (), {
                    'name': 'vnormals',
                    'datatype': 'normals3D',
                    'height': 8,
                    'width': 12,
                    'shape': 'rect',
                    'color': 'blue'
                })
            MSMS_WS.host = self.host
            MSMS_WS.opal_service = self.opal_service

            code = """def doit(self, input_str, probe_radius, density, allComp, getfile):
    self.opal_service.inputFile.Set_name('msms.xyzr')
    self.opal_service.inputFile.Set_contents(input_str)
    options = '-if msms.xyzr -of ws_out '
    options += '-probe_radius ' + str(probe_radius)
    options += ' -density ' + str(density)
    if allComp:
        options += ' -all_components'
    self.opal_service.req._argList = options
    inputFiles = []
    inputFiles.append(self.opal_service.inputFile)
    self.opal_service.req._inputFile = inputFiles
    resp = self.opal_service.run('msmsServicePort')
    if resp:
        for files in resp._outputFile:
            if files._url.split('/')[-1] == 'ws_out.face':
                face_file = files._url
            if files._url.split('/')[-1] == 'ws_out.vert':
                vert_file = files._url
        if getfile:           
            from Pmv.msmsParser import MSMSParser
            msmsParser = MSMSParser()
            import urllib
            opener = urllib.FancyURLopener({})
            in_file = opener.open(face_file)
            msmsParser.getFaces(in_file.readlines())
            in_file = opener.open(vert_file)
            msmsParser.getVert(in_file.readlines())
            self.outputData(vertices = msmsParser.vertices, indices = msmsParser.faces,
                          vnormals = msmsParser.normals)
        else:
            self.outputData(vertices = vert_file, indices = face_file,
                          vnormals = None)
"""
            MSMS_WS.configure(function=code)
        except:
            print "WARNING: failed to restore Generic named MSMS WS in network self.macroNetwork"
            print_exc()
            MSMS_WS = None
        self.macroNetwork.freeze()

        ## saving connections for network WebMSMS ##
        if Assign_Radii is not None and Select_Nodes is not None:
            self.macroNetwork.connectNodes(Assign_Radii,
                                           Select_Nodes,
                                           "molecules",
                                           "nodes",
                                           blocking=True)
        if Select_Nodes is not None and Get_xyzr is not None:
            self.macroNetwork.connectNodes(Select_Nodes,
                                           Get_xyzr,
                                           "nodes",
                                           "atoms",
                                           blocking=True)
        if Get_xyzr is not None and MSMS_WS is not None:
            self.macroNetwork.connectNodes(Get_xyzr,
                                           MSMS_WS,
                                           "output",
                                           "input_str",
                                           blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(MSMS_WS,
                                           IndexedPolygons,
                                           "vertices",
                                           "coords",
                                           blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(MSMS_WS,
                                           IndexedPolygons,
                                           "indices",
                                           "indices",
                                           blocking=True)
        if MSMS_WS is not None and IndexedPolygons is not None:
            self.macroNetwork.connectNodes(MSMS_WS,
                                           IndexedPolygons,
                                           "vnormals",
                                           "vnormals",
                                           blocking=True)
        output_Ports = self.macroNetwork.opNode
        if IndexedPolygons is not None and output_Ports is not None:
            self.macroNetwork.connectNodes(IndexedPolygons,
                                           output_Ports,
                                           "indexedPolygons",
                                           "new",
                                           blocking=True)
        input_Ports = self.macroNetwork.ipNode
        if input_Ports is not None and Assign_Radii is not None:
            self.macroNetwork.connectNodes(input_Ports,
                                           Assign_Radii,
                                           "new",
                                           "molecules",
                                           blocking=True)
        self.macroNetwork.unfreeze()

        WebMSMS.shrink()

        ## reset modifications ##
        WebMSMS.resetTags()
        WebMSMS.buildOriginalList()