Пример #1
0
def readOne(fname, gname, scene):
    #    iscene = Cmaxwell(mwcallback);
    filename = autopack.retrieveFile(fname, cache="geoms")  #geometries
    ok = scene.readMXS(str(filename))
    if not ok:
        print "problem reading", filename
    obj = scene.getObject(str(gname))[0]
    #    print obj,gname
    #    obj2 = scene.addObject(obj);
    #    iscene.freeScene();
    return obj, scene
Пример #2
0
def buildCompartmentsGeomRep(comp, collada_xml, root_node, mask=None):
    if comp.representation_file is None:
        return collada_xml, root_node
    nr = scene.Node(str(comp.name) + str("rep"))
    filename = autopack.retrieveFile(comp.representation_file,
                                     cache="geometries")  #geometries
    gdic = helper.read(filename)
    for nid in gdic:
        matnode = oneMaterial(str(nid), collada_xml, color=gdic[nid]["color"])
        master_node = colladaMesh(str(nid),
                                  gdic[nid]["mesh"][0],
                                  gdic[nid]["mesh"][1],
                                  gdic[nid]["mesh"][2],
                                  collada_xml,
                                  matnode=matnode)
        #        master_node = colladaMesh(str(nid),comp.vertices,comp.vnormals,comp.faces,collada_xml,matnode=matnode)
        collada_xml.nodes.append(master_node)
        #        mxmesh.setParent(nr)
        if len(gdic[nid]['instances']):
            geomnode = scene.NodeNode(master_node)
            #            !n=scene.Node(str(nid)+str("instances"))
            #            nri.setParent(nr)
            g = []
            c = 0
            for mat in gdic[nid]['instances']:
                geomnode = scene.NodeNode(master_node)
                #                instance = scene.createInstancement(str(nid)+"_"+str(c),mxmesh)
                mat = numpy.array(mat, float)  #.transpose()
                if helper.host == 'dejavu':  #need to find the way that will work everywhere
                    mry90 = helper.rotation_matrix(-math.pi / 2.0,
                                                   [0.0, 1.0, 0.0])  #?
                    mat = numpy.array(numpy.matrix(mat) * numpy.matrix(mry90))
                    # mat = numpy.array(mat).transpose()
                scale, shear, euler, translate, perspective = decompose_matrix(
                    mat)
                p = translate  #matrix[3,:3]/100.0#unit problem
                tr = scene.TranslateTransform(p[0], p[1], p[2])
                rx = scene.RotateTransform(1, 0, 0, numpy.degrees(euler[0]))
                ry = scene.RotateTransform(0, 1, 0, numpy.degrees(euler[1]))
                rz = scene.RotateTransform(0, 0, 1, numpy.degrees(euler[2]))
                s = scene.ScaleTransform(scale[0], scale[1], scale[2])
                ne = scene.Node(str(nid) + "_" + str(c),
                                children=[
                                    geomnode,
                                ],
                                transforms=[tr, rz, ry, rx,
                                            s])  #scene.MatrixTransform(matrix)
                g.append(ne)
                c += 1
            node = scene.Node(str(nid) + str("instances"), children=g)
            nr.children.append(node)
    root_node.children.append(nr)
    return collada_xml, root_node
Пример #3
0
useXref = True
mixedJson = True
HIV = False
#def convertOneRecipe()

if len(sys.argv) > 1:
    filename = sys.argv[1]
    resultfile = None
    if filename in autopack.RECIPES:
        n = filename
        v = sys.argv[2]
        filename = autopack.RECIPES[n][v]["setupfile"]
        resultfile = autopack.RECIPES[n][v]["resultfile"]
    else:
        resultfile = sys.argv[2]
    setupfile = autopack.retrieveFile(filename, cache="recipes")
    print("ok use ", setupfile, filename, resultfile)
    fileName, fileExtension = os.path.splitext(setupfile)
    n = os.path.basename(fileName)
    h = Environment(name=n)
    h.loadRecipe(setupfile)
    h.setupfile = filename
    if resultfile is not None:
        h.resultfile = resultfile
    fileName, fileExtension = os.path.splitext(setupfile)
    if export_json:
        print("expot json recipe ", fileName)
        h.saveRecipe(fileName + ".json", useXref=useXref, indent=True)
    if check_result:
        rfile = h.resultfile
        resultfilename = autopack.retrieveFile(rfile, cache="results")
Пример #4
0
        print ingr.o_name, "removed"


doit = True
import datetime
i = datetime.datetime.now()
#update the json dic if wrong center info
if len(sys.argv) > 1:
    filename = sys.argv[1]
    resultfile = None
    if filename in autopack.RECIPES:
        n = filename
        v = sys.argv[2]
        filename = autopack.RECIPES[n][v]["setupfile"]
        resultfile = autopack.RECIPES[n][v]["resultfile"]
        setupfile = autopack.retrieveFile(filename, cache="recipes")
    else:
        setupfile = filename
    #overwrite result file
    resultfile = "output_autopack_test"
    print("ok use ", setupfile, filename)
    fileName, fileExtension = os.path.splitext(setupfile)
    print fileName
    n = os.path.basename(fileName)
    recipe = n
    h = Environment(name=n)
    h.loadRecipe(setupfile)
    h.setupfile = filename
    if resultfile is not None:
        h.resultfile = resultfile
    h.saveResult = False
Пример #5
0
#    mesh=None
#    if MAYA:
#        mesh=helper.getObject("HIV1_capsid_3j3q_Rep_Med_0_1_0")
#    collada_xml=helper.instancesToCollada(parent_object,collada_xml=collada_xml,instance_node=True,parent_node=node,mesh=mesh)
#    #collada_xml.scene.nodes
#    collada_xml.write("/Users/ludo/DEV/autopack_git/autoPACK_database_1.0.0/geometries/HIV1_capside_3j3q_Rep_Med_0_2_1.dae")

resultfile = None
if len(sys.argv) > 1:
    filename = sys.argv[1]
    if filename in autopack.RECIPES:
        n = filename
        v = sys.argv[2]
        filename = autopack.RECIPES[n][v]["setupfile"]
        resultfile = autopack.RECIPES[n][v]["resultfile"]
    setupfile = autopack.retrieveFile(filename, cache="recipes")
    print("ok use ", setupfile, filename)
    fileName, fileExtension = os.path.splitext(setupfile)
    n = os.path.basename(fileName)
else:
    setupfile = filename = "C:\Users\ludov\Google Drive\TSRI HIV Modeling\HIVsphere_simple_r140.json"
    #    resultfile = "C:\Users\ludov\Google Drive\TSRI HIV Modeling\cellpack_models\Sphere_140_m330_random_tr.json"
    #    resultfile = "C:\Users\ludov\Google Drive\TSRI HIV Modeling\cellpack_models\Sphere_140_10_random_tr.json"
    resultfile = "C:\Users\ludov\Google Drive\TSRI HIV Modeling\cellpack_models\HIV_VLP_140_214_random_tr.json"
    #    resultfile = "C:\Users\ludov\OneDrive\Documents\\backupC4DHiv\sphere140_rand_49_tr.json"
    #    setupfile = filename = "C:\Users\ludov\Google Drive\TSRI HIV Modeling\HIVsphere_simple_r139.json"
    #    resultfile = "C:\Users\ludov\OneDrive\Documents\\backupC4DHiv\sphere139_random_127_tr.json"
    n = "HIV_VLP"
h = Environment(name=n)
h.loadRecipe(setupfile)
h.setupfile = filename
Пример #6
0
def buildCompartmentsGeom(comp, scene, parent=None):
    if comp.representation_file is None:
        return
    nr = scene.createNullObject(str(comp.name) + str("rep"))
    if parent is not None:
        nr.setParent(parent)
    filename = autopack.retrieveFile(comp.representation_file,
                                     cache="geoms")  #geometries
    gdic = helper.read(filename)
    for nid in gdic:
        matnode = oneMaterial(str(nid), scene, color=gdic[nid]["color"])
        mxmesh = maxwellMesh(str(nid),
                             gdic[nid]["mesh"][0],
                             gdic[nid]["mesh"][1],
                             gdic[nid]["mesh"][2],
                             scene,
                             matnode=matnode)
        mxmesh.setParent(nr)
        if len(gdic[nid]['instances']):
            nri = scene.createNullObject(str(nid) + str("instances"))
            nri.setParent(nr)
            c = 0
            for mat in gdic[nid]['instances']:
                instance = scene.createInstancement(
                    str(nid) + "_" + str(c), mxmesh)
                mat = numpy.array(mat, float).transpose()
                scale, shear, euler, translate, perspective = decompose_matrix(
                    mat)
                base, pivot, ok = instance.getBaseAndPivot()
                base.origin = Cvector(float(mat[3][0]), float(mat[3][1]),
                                      float(mat[3][2]))
                mat[3, :3] = [0., 0., 0.]
                #                mat = numpy.array(mat,float).transpose()
                newaxis = helper.ApplyMatrix(
                    [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], mat)

                base.xAxis = Cvector(float(newaxis[0][0]),
                                     float(newaxis[0][1]),
                                     float(newaxis[0][2]))
                base.yAxis = Cvector(float(newaxis[1][0]),
                                     float(newaxis[1][1]),
                                     float(newaxis[1][2]))
                base.zAxis = Cvector(float(newaxis[2][0]),
                                     float(newaxis[2][1]),
                                     float(newaxis[2][2]))
                #                base.xAxis=Cvector(float(mat[0][0]),float(mat[1][0]),float(mat[2][0]))
                #                base.yAxis=Cvector(float(mat[0][1]),float(mat[1][1]),float(mat[2][1]))
                #                base.zAxis=Cvector(float(mat[0][2]),float(mat[1][2]),float(mat[2][2]))\
                #                base.xAxis=Cvector(float(mat[0][0]),float(mat[0][1]),float(mat[0][2]))
                #                base.yAxis=Cvector(float(mat[1][0]),float(mat[1][1]),float(mat[1][2]))
                #                base.zAxis=Cvector(float(mat[2][0]),float(mat[2][1]),float(mat[2][2]))
                base.xAxis.normalize()
                base.yAxis.normalize()
                base.zAxis.normalize()

                #                base.origin = Cvector(float(mat[0][3]),float(mat[1][3]),float(mat[2][3]))
                #                print ("X",mat[0][0],mat[0][1],mat[0][2],base.xAxis.x(),base.xAxis.y(),base.xAxis.z())
                #                print ("Y",mat[1][0],mat[1][1],mat[1][2],base.yAxis.x(),base.yAxis.y(),base.yAxis.z())
                #                print ("Z",mat[2][0],mat[2][1],mat[2][2],base.zAxis.x(),base.zAxis.y(),base.zAxis.z())
                #                print ("base",mat[3][0],mat[3][1],mat[3][2],base.origin.x(),base.origin.y(),base.origin.z())
                instance.setBaseAndPivot(base, base)
                #                pos=Cvector(float(mat[3][0]),float(mat[3][1]),float(mat[3][2]))
                #                eul=Cvector(float(euler[0]),float(euler[1]),float(euler[2]))
                #                instance.setPosition(pos)
                #                instance.setRotation(eul)
                #                instance.setParent(nri)
                #                wt=instance.getWorldTransform()[0]
                print str(nid) + "_" + str(c), mat
                #                print wt.origin.x(),wt.origin.y(),wt.origin.z(),float(mat[3][0]),float(mat[3][1]),float(mat[3][2])
                #                print wt.xAxis.x(),wt.xAxis.y(),wt.xAxis.z()
                #                print wt.yAxis.x(),wt.yAxis.y(),wt.yAxis.z()
                #                print wt.zAxis.x(),wt.zAxis.y(),wt.zAxis.z()
                #                print instance.getPosition()[0]
                #                print instance.getRotation()[0]
                #                base,pivot,ok = instance.getBaseAndPivot();
                if c == 5:
                    #                    print ("X",mat,base.xAxis.x(),base.xAxis.y(),base.xAxis.z())
                    break
                c += 1