示例#1
0
    def addToModel(self,position=[0,0,0],parent=None):
        if parent is None:
            parent = context.application.model.universe

        fragmentdir = context.get_share_filename('fragments')
        filename = fragmentdir+'/'+self.name+'.cml'

        from molmod.io.cml import load_cml
        molecules = load_cml(filename)
        molecule = molecules[0] #we only look at first molecule in the list

        #load 'universe' from file trough cml load filter (stolen from models.py > file_open)
        load_filter = context.application.plugins.get_load_filter('cml')

        #create frame
        Frame = context.application.plugins.get_node("Frame")
        self.fragment_frame = Frame(name=self.name)

        #fill frame with molecule
        load_filter.load_molecule(self.fragment_frame,molecule)

        #rotate frame?
        rotation = numpy.array([[1,2,0],
                                [0,0,0],
                                 [0,0,0]])
        # self.fragment_frame.transformation.r[:] = rotation

        print self.fragment_frame.transformation.r

        #apply transformation to frame
        self.fragment_frame.transformation.t[:] = position

        #add to model (note: should add to parent frame, not universe)
        primitive.Add(self.fragment_frame, parent)
示例#2
0
    def get_in_frame(self,position):

        fragmentdir = context.get_share_filename('fragments')
        filename = fragmentdir+'/'+self.name+'.cml'

        from molmod.io.cml import load_cml
        molecules = load_cml(filename)
        molecule = molecules[0] #we only look at first molecule in the list

        #load 'universe' from file trough cml load filter (stolen from models.py > file_open)
        load_filter = context.application.plugins.get_load_filter('cml')

        #create frame
        Frame = context.application.plugins.get_node("Frame")
        self.fragment_frame = Frame(name=self.name)

        #fill frame with molecule
        load_filter.load_molecule(self.fragment_frame,molecule)

        #rotate frame?
        rotation = numpy.array([[1,2,0],
                                [0,0,0],
                                 [0,0,0]])
        # self.fragment_frame.transformation.r[:] = rotation

        print self.fragment_frame.transformation.r

        #apply transformation to frame
        self.fragment_frame.transformation.t[:] = position

        return self.fragment_frame
示例#3
0
    def get_fragment(self, fragmentname):
        fragmentdir = context.get_share_filename('fragments')
        filename = fragmentdir+'/'+fragmentname+'.cml'

        molecules = load_cml(filename)
        molecule = molecules[0]

        Frame = context.application.plugins.get_node("Frame")
        fragment_frame = Frame(name=fragmentname)

        load_filter = context.application.plugins.get_load_filter('cml')
        load_filter.load_molecule(fragment_frame,molecule)

        return fragment_frame
示例#4
0
    def __call__(self, f):
        Universe = context.application.plugins.get_node("Universe")
        universe = Universe()
        Folder = context.application.plugins.get_node("Folder")
        folder = Folder()

        Frame = context.application.plugins.get_node("Frame")

        molecules = load_cml(f)

        if len(molecules) == 1:
            molecule = molecules[0]
            universe.name = molecule.title
            self.load_molecule(universe, molecule)
        else:
            for molecule in molecules:
                parent = Frame(name=molecule.title)
                universe.add(parent)
                self.load_molecule(parent, molecule)

        return [universe, folder]