コード例 #1
0
def restoreMolecules(srcMolInfo, defRadii, radiiExceptions):
	from tempfile import mktemp
	import os
	from SimpleSession import modelMap, modelOffset
	for mid, subid, name, fileContents in srcMolInfo:
		fname = mktemp()
		f = file(fname, "w")
		f.write(fileContents)
		f.close() # force a flush
		mols = chimera.openModels.open(fname, type="session PDB",
                        baseId=mid+modelOffset, subid=subid, identifyAs=name)
		os.unlink(fname)
			
		if mols:
			globals.atomIDs.update(mols[0].sessionIDs)
			delattr(mols[0], 'sessionIDs')
			modelMap.setdefault((mid, subid), []).extend(mols)


	for mList in modelMap.values():
		for m in mList:
			for a in m.atoms:
				try:
					a.radius = defRadii[a.idatmType]
				except KeyError:
					continue
	for aID, rad in radiiExceptions:
		idLookup(aID).radius = float(rad)
コード例 #2
0
ファイル: v23.py プロジェクト: davem22101/semanticscience
def restoreVRML(vrmlInfo):
	sm = globals.sessionMap
	for id, subid, name, display, vrmlString in zip(
					expandSummary(vrmlInfo['id']),
					expandSummary(vrmlInfo['subid']),
					expandSummary(vrmlInfo['name']),
					expandSummary(vrmlInfo['display']),
					vrmlInfo['vrmlString']
					):
		from SimpleSession import modelMap, modelOffset
		if (id, subid) in modelMap:
			model = modelMap[(id, subid)][0]
			mapId, mapSubid = model.id, model.subid
		else:
			mapId, mapSubid = id+modelOffset, subid
		if not vrmlString.startswith("#VRML"):
			# BILD object
			from Bld2VRML.bld2vrml import Environment
			env = Environment()
			for line in vrmlString.splitlines():
				env.handleLine(line)
			env.finish()
			vrmlString = env.buildVRML()
		vrmlModels = chimera.openModels.open(vrmlString, type="VRML",
				baseId=mapId, subid=mapSubid, identifyAs=name)
		for vrml in vrmlModels:
			vrml.display = display
			sm[len(sm)] = vrml
		modelMap.setdefault((id, subid), []).extend(vrmlModels)
コード例 #3
0
def restoreVRML(vrmlInfo):
    sm = globals.sessionMap
    for id, subid, name, display, vrmlString in zip(
            expandSummary(vrmlInfo['id']), expandSummary(vrmlInfo['subid']),
            expandSummary(vrmlInfo['name']),
            expandSummary(vrmlInfo['display']), vrmlInfo['vrmlString']):
        from SimpleSession import modelMap, modelOffset
        if (id, subid) in modelMap:
            model = modelMap[(id, subid)][0]
            mapId, mapSubid = model.id, model.subid
        else:
            mapId, mapSubid = id + modelOffset, subid
        if not vrmlString.startswith("#VRML"):
            # BILD object
            from Bld2VRML.bld2vrml import Environment
            env = Environment()
            for line in vrmlString.splitlines():
                env.handleLine(line)
            env.finish()
            vrmlString = env.buildVRML()
        vrmlModels = chimera.openModels.open(vrmlString,
                                             type="VRML",
                                             baseId=mapId,
                                             subid=mapSubid,
                                             identifyAs=name)
        for vrml in vrmlModels:
            vrml.display = display
            sm[len(sm)] = vrml
        modelMap.setdefault((id, subid), []).extend(vrmlModels)
コード例 #4
0
    def restore_state(self, model):

        model.name = self.name
        model.display = self.display
        model.openState.xform = self.xform.create_object()
        model.openState.active = self.active

        #
        # Record how model id number has been remapped.
        #
        if self.version >= 2:
            from SimpleSession import modelMap
            modelMap.setdefault((self.id, self.subid), []).append(model)
        else:
            from SimpleSession import updateOSLmap
            updateOSLmap(self.osl_identifier, model.oslIdent())

        if self.version >= 3:
            p = model.clipPlane
            import chimera
            p.origin = chimera.Point(*self.clip_plane_origin)
            n = chimera.Vector(*self.clip_plane_normal)
            if n.length == 0:
                n = chimera.Vector(0, 0, -1)
            p.normal = n
            model.clipPlane = p
            model.clipThickness = self.clip_thickness
            model.useClipPlane = self.use_clip_plane
            if self.version >= 4:
                model.useClipThickness = self.use_clip_thickness
コード例 #5
0
def restoreVRML(info):
        from SimpleSession import modelOffset
	for idInfo, vrmlString in info.items():
		id, subid, name = idInfo
		from SimpleSession import modelMap
		if (id, subid) in modelMap:
			model = modelMap[(id, subid)][0]
			mapId, mapSubid = model.id, model.subid
		else:
			mapId, mapSubid = id+modelOffset, subid
		vrmlModels = chimera.openModels.open(vrmlString, type="VRML",
				baseId=mapId, subid=mapSubid, identifyAs=name)
		modelMap.setdefault((id, subid), []).extend(vrmlModels)
コード例 #6
0
def restoreSurfaces(surfDisplayed, surfCategories, surfDict):
    for surfDisp in surfDisplayed:
        idLookup(surfDisp).surfaceDisplay = 1
    for category, atList in surfCategories.items():
        for a in atList:
            idLookup(a).surfaceCategory = category
    for molID, attrs in surfDict.items():
        mol = idLookup(molID)
        surf = chimera.MSMSModel(mol, attrs['category'])
        del attrs['category']
        for attr, val in attrs.items():
            setattr(surf, attr, val)
        chimera.openModels.add([surf], sameAs=mol)
        from SimpleSession import modelMap
        modelMap.setdefault((mol.id, mol.subid), []).append(surf)
コード例 #7
0
ファイル: v15.py プロジェクト: davem22101/semanticscience
def restoreSurfaces(surfDisplayed, surfCategories, surfDict, surfOpacity):
	for surfDisp in surfDisplayed:
		idLookup(surfDisp).surfaceDisplay = 1
	for category, atList in surfCategories.items():
		for a in atList:
			idLookup(a).surfaceCategory = category
	for molID, attrs in surfDict.items():
		mol = idLookup(molID)
		surf = chimera.MSMSModel(mol, attrs['category'])
		del attrs['category']
		for attr, val in attrs.items():
			if attr == 'customColors':
				val = map(getColor, val)
			setattr(surf, attr, val)
		chimera.openModels.add([surf], sameAs=mol)
		from SimpleSession import modelMap
		modelMap.setdefault((mol.id, mol.subid), []).append(surf)

	for atomID, opacity in surfOpacity.items():
		atom = idLookup(atomID)
		atom.surfaceOpacity = opacity
コード例 #8
0
def restoreSurfaces(surfDisplayed, surfCategories, surfDict, surfOpacity):
    for surfDisp in surfDisplayed:
        idLookup(surfDisp).surfaceDisplay = 1
    for category, atList in surfCategories.items():
        for a in atList:
            idLookup(a).surfaceCategory = category
    for molID, attrs in surfDict.items():
        mol = idLookup(molID)
        surf = chimera.MSMSModel(mol, attrs['category'])
        del attrs['category']
        for attr, val in attrs.items():
            if attr == 'customColors':
                val = map(getColor, val)
            setattr(surf, attr, val)
        chimera.openModels.add([surf], sameAs=mol)
        from SimpleSession import modelMap
        modelMap.setdefault((mol.id, mol.subid), []).append(surf)

    for atomID, opacity in surfOpacity.items():
        atom = idLookup(atomID)
        atom.surfaceOpacity = opacity
コード例 #9
0
def restoreSurfaces(surfInfo):
    sm = globals.sessionMap
    for mid, category, colorMode, density, name, drawMode, display, \
    probeRadius, customColorsSummary, allComponents in zip(
        surfInfo['molecule'],
        expandSummary(surfInfo['category']),
        expandSummary(surfInfo['colorMode']),
        expandSummary(surfInfo['density']),
        surfInfo['name'],
        expandSummary(surfInfo['drawMode']),
        expandSummary(surfInfo['display']),
        expandSummary(surfInfo['probeRadius']),
        surfInfo['customColors'],
        expandSummary(surfInfo['allComponents'])
        ):
        mol = idLookup(mid)
        s = chimera.MSMSModel(mol, category, allComponents=allComponents)
        chimera.openModels.add([s], sameAs=mol)
        s.colorMode = colorMode
        s.density = density
        s.name = name
        s.drawMode = drawMode
        s.display = display
        s.probeRadius = probeRadius
        customColors = expandSummary(customColorsSummary)
        if customColors:
            if len(customColors) != len(s.triangleData()[0]):
                from chimera import replyobj
                replyobj.error(
                    "Number of surface vertices for %s (%s) differs from number of colors.\nCustom color scheme not restored\n"
                    % (mol.oslIdent(), category))
                s.colorMode = chimera.MSMSModel.ByAtom
            else:
                s.customColors = [getColor(c) for c in customColors]
                # setting custom colors seems to implicitly
                # set the color mode...
                s.colorMode = colorMode
        sm[len(sm)] = s
        from SimpleSession import modelMap
        modelMap.setdefault((mol.id, mol.subid), []).append(s)
コード例 #10
0
ファイル: v37.py プロジェクト: davem22101/semanticscience
def restoreSurfaces(surfInfo):
	sm = globals.sessionMap
	for mid, category, colorMode, density, name, drawMode, display, \
	probeRadius, customColorsSummary, allComponents in zip(
					surfInfo['molecule'],
					expandSummary(surfInfo['category']),
					expandSummary(surfInfo['colorMode']),
					expandSummary(surfInfo['density']),
					surfInfo['name'],
					expandSummary(surfInfo['drawMode']),
					expandSummary(surfInfo['display']),
					expandSummary(surfInfo['probeRadius']),
					surfInfo['customColors'],
					expandSummary(surfInfo['allComponents'])
					):
		mol = idLookup(mid)
		s = chimera.MSMSModel(mol, category,
					allComponents=allComponents)
		chimera.openModels.add([s], sameAs=mol)
		s.colorMode = colorMode
		s.density = density
		s.name = name
		s.drawMode = drawMode
		s.display = display
		s.probeRadius = probeRadius
		customColors = expandSummary(customColorsSummary)
		if customColors:
			if len(customColors) != len(s.triangleData()[0]):
				from chimera import replyobj
				replyobj.error("Number of surface vertices for %s (%s) differs from number of colors.\nCustom color scheme not restored\n" % (mol.oslIdent(), category))
				s.colorMode = chimera.MSMSModel.ByAtom
			else:
				s.customColors = [getColor(c)
							for c in customColors]
				# setting custom colors seems to implicitly
				# set the color mode...
				s.colorMode = colorMode
		sm[len(sm)] = s
		from SimpleSession import modelMap
		modelMap.setdefault((mol.id, mol.subid), []).append(s)
コード例 #11
0
def restoreMolecules(srcMolMap):
    from tempfile import mktemp
    import os
    from SimpleSession import modelOffset
    for idInfo, fileContents in srcMolMap.items():
        fname = mktemp()
        f = file(fname, "w")
        f.write(fileContents)
        f.close()  # force a flush
        mid, subid, name = idInfo
        mols = chimera.openModels.open(fname,
                                       type="session PDB",
                                       baseId=mid + modelOffset,
                                       subid=subid,
                                       identifyAs=name)
        os.unlink(fname)

        if mols:
            globals.atomIDs.update(mols[0].sessionIDs)
            delattr(mols[0], 'sessionIDs')
            from SimpleSession import modelMap
            modelMap.setdefault((mid, subid), []).extend(mols)
コード例 #12
0
def restoreSurfaces(surfInfo):
    sm = globals.sessionMap
    si = {}
    for n in ('molecule', 'name', 'customColors'):
        si[n] = surfInfo[n]
    for n in ('category', 'colorMode', 'density', 'drawMode', 'display',
              'probeRadius', 'allComponents', 'lineWidth', 'pointSize',
              'useLighting', 'twoSidedLighting', 'smoothLines',
              'transparencyBlendMode', 'oneTransparentLayer'):
        si[n] = expandSummary(surfInfo[n])
    for i, mid in enumerate(si['molecule']):
        mol = idLookup(mid)
        s = chimera.MSMSModel(mol,
                              si['category'][i],
                              probeRadius=si['probeRadius'][i],
                              allComponents=si['allComponents'][i],
                              vertexDensity=si['density'][i])
        chimera.openModels.add([s], sameAs=mol)
        for n in ('name', 'colorMode', 'drawMode', 'display', 'lineWidth',
                  'pointSize', 'useLighting', 'twoSidedLighting',
                  'smoothLines', 'transparencyBlendMode',
                  'oneTransparentLayer'):
            setattr(s, n, si[n][i])
        customColors = expandSummary(si['customColors'][i])
        if customColors:
            if len(customColors) != len(s.triangleData()[0]):
                from chimera import replyobj
                replyobj.error(
                    "Number of surface vertices for %s (%s) differs from number of colors.\nCustom color scheme not restored\n"
                    % (mol.oslIdent(), category))
                s.colorMode = chimera.MSMSModel.ByAtom
            else:
                s.customColors = [getColor(c) for c in customColors]
                # setting custom colors seems to implicitly
                # set the color mode...
                s.colorMode = si['colorMode'][i]
        sm[len(sm)] = s
        from SimpleSession import modelMap
        modelMap.setdefault((mol.id, mol.subid), []).append(s)
コード例 #13
0
ファイル: v40.py プロジェクト: davem22101/semanticscience
def restoreSurfaces(surfInfo):
	sm = globals.sessionMap
        si = {}
        for n in ('molecule', 'name', 'customColors'):
            si[n] = surfInfo[n]
        for n in ('category', 'colorMode', 'density', 'drawMode',
                  'display', 'probeRadius', 'allComponents',
                  'lineWidth', 'pointSize', 'useLighting',
                  'twoSidedLighting', 'smoothLines',
                  'transparencyBlendMode', 'oneTransparentLayer'):
            si[n] = expandSummary(surfInfo[n])
        for i, mid in enumerate(si['molecule']):
		mol = idLookup(mid)
		s = chimera.MSMSModel(mol, si['category'][i],
                                      probeRadius = si['probeRadius'][i],
                                      allComponents = si['allComponents'][i],
                                      vertexDensity = si['density'][i])
		chimera.openModels.add([s], sameAs=mol)
                for n in ('name', 'colorMode', 'drawMode', 'display',
                          'lineWidth', 'pointSize', 'useLighting',
                          'twoSidedLighting', 'smoothLines',
                          'transparencyBlendMode', 'oneTransparentLayer'):
                    setattr(s, n, si[n][i])
		customColors = expandSummary(si['customColors'][i])
		if customColors:
			if len(customColors) != len(s.triangleData()[0]):
				from chimera import replyobj
				replyobj.error("Number of surface vertices for %s (%s) differs from number of colors.\nCustom color scheme not restored\n" % (mol.oslIdent(), category))
				s.colorMode = chimera.MSMSModel.ByAtom
			else:
				s.customColors = [getColor(c)
							for c in customColors]
				# setting custom colors seems to implicitly
				# set the color mode...
				s.colorMode = si['colorMode'][i]
		sm[len(sm)] = s
		from SimpleSession import modelMap
		modelMap.setdefault((mol.id, mol.subid), []).append(s)
コード例 #14
0
ファイル: v25.py プロジェクト: davem22101/semanticscience
def restoreMolecules(molInfo, resInfo, atomInfo, bondInfo, crdInfo):
	items = []
	sm = globals.sessionMap

	res2mol = []
	atom2mol = []
	openModelsArgs = {}
	for ids, name, cid, display, lineWidth, pointSize, stickScale, \
	pdbHeaders, surfaceOpacity, ballScale, vdwDensity, autochain, \
	ribbonHidesMainchain in zip(
				expandSummary(molInfo['ids']),
				expandSummary(molInfo['name']),
				expandSummary(molInfo['color']),
				expandSummary(molInfo['display']),
				expandSummary(molInfo['lineWidth']),
				expandSummary(molInfo['pointSize']),
				expandSummary(molInfo['stickScale']),
				molInfo['pdbHeaders'],
				expandSummary(molInfo['surfaceOpacity']),
				expandSummary(molInfo['ballScale']),
				expandSummary(molInfo['vdwDensity']),
				expandSummary(molInfo['autochain']),
				expandSummary(molInfo['ribbonHidesMainchain'])
				):
		m = chimera.Molecule()
		sm[len(items)] = m
		items.append(m)
		m.name = name
		from SimpleSession import modelMap, modelOffset
		chimera.openModels.add([m],
				baseId=ids[0]+modelOffset, subid=ids[1])
		modelMap.setdefault(ids, []).append(m)
		m.color = getColor(cid)
		m.display = display
		m.lineWidth = lineWidth
		m.pointSize = pointSize
		m.stickScale = stickScale
		m.setAllPDBHeaders(pdbHeaders)
		m.surfaceOpacity = surfaceOpacity
		m.ballScale = ballScale
		m.vdwDensity = vdwDensity
		m.autochain = autochain
		m.ribbonHidesMainchain = ribbonHidesMainchain
	if molInfo['optional']:
		for attrName, info in molInfo['optional'].items():
			for a, val in zip(items, expandSummary(info)):
				if val is not None:
					setattr(a, attrName, val)

	resStart = len(items)
	for mid, name, chain, pos, insert, rcid, lcid, ss, ribbonDrawMode, \
	ribbonDisplay, label in zip(
				expandSummary(resInfo['molecule']),
				expandSummary(resInfo['name']),
				expandSummary(resInfo['chain']),
				resInfo['position'],
				expandSummary(resInfo['insert']),
				expandSummary(resInfo['ribbonColor']),
				expandSummary(resInfo['labelColor']),
				expandSummary(resInfo['ss']),
				expandSummary(resInfo['ribbonDrawMode']),
				expandSummary(resInfo['ribbonDisplay']),
				expandSummary(resInfo['label'])
				):
		m = idLookup(mid)
		r = m.newResidue(name, chain, pos, insert)
		sm[len(items)] = r
		items.append(r)
		r.ribbonColor = getColor(rcid)
		r.labelColor = getColor(lcid)
		r.isHelix, r.isStrand, r.isTurn = ss
		r.ribbonDrawMode = ribbonDrawMode
		r.ribbonDisplay = ribbonDisplay
		r.label = label
	if resInfo['optional']:
		residues = items[resStart:]
		for attrName, info in resInfo['optional'].items():
			for a, val in zip(residues, expandSummary(info)):
				if val is not None:
					setattr(a, attrName, val)

	atomStart = len(items)
	for rid, name, element, cid, vcid, lcid, scid, drawMode, display, \
	label, surfaceDisplay, surfaceCategory, surfaceOpacity, radius, vdw, \
	idatmType in zip(
				expandSummary(atomInfo['residue']),
				expandSummary(atomInfo['name']),
				expandSummary(atomInfo['element']),
				expandSummary(atomInfo['color']),
				expandSummary(atomInfo['vdwColor']),
				expandSummary(atomInfo['labelColor']),
				expandSummary(atomInfo['surfaceColor']),
				expandSummary(atomInfo['drawMode']),
				expandSummary(atomInfo['display']),
				expandSummary(atomInfo['label']),
				expandSummary(atomInfo['surfaceDisplay']),
				expandSummary(atomInfo['surfaceCategory']),
				expandSummary(atomInfo['surfaceOpacity']),
				expandSummary(atomInfo['radius']),
				expandSummary(atomInfo['vdw']),
				expandSummary(atomInfo['idatmType'])
				):
		r = idLookup(rid)
		a = r.molecule.newAtom(name, chimera.Element(element))
		sm[len(items)] = a
		items.append(a)
		r.addAtom(a)
		a.color = getColor(cid)
		a.vdwColor = getColor(vcid)
		a.labelColor = getColor(lcid)
		a.surfaceColor = getColor(scid)
		a.drawMode = drawMode
		a.display = display
		a.label = label
		a.surfaceDisplay = surfaceDisplay
		a.surfaceCategory = surfaceCategory
		a.surfaceOpacity = surfaceOpacity
		a.radius = radius
		a.vdw = vdw
		if idatmType:
			a.idatmType = idatmType
	if atomInfo['optional']:
		atoms = items[atomStart:]
		for attrName, info in atomInfo['optional'].items():
			for a, val in zip(atoms, expandSummary(info)):
				if val is not None:
					setattr(a, attrName, val)

	for atoms, drawMode, display in zip(
					bondInfo['atoms'],
					expandSummary(bondInfo['drawMode']),
					expandSummary(bondInfo['display'])
					):
		a1, a2 = [idLookup(a) for a in atoms]
		b = a1.molecule.newBond(a1, a2)
		sm[len(items)] = b
		items.append(b)
		b.drawMode = drawMode
		b.display = display

	from chimera import Point
	for mid, crdSets in crdInfo.items():
		m = idLookup(mid)
		active = crdSets.pop('active')
		for key, crds in crdSets.items():
			coordSet = m.newCoordSet(key, len(crds))
			for aid, crdString in crds:
				idLookup(aid).setCoord(Point(*tuple([float(c)
					for c in crdString.split()])), coordSet)
			if key == active:
				m.activeCoordSet = coordSet
コード例 #15
0
def restoreMolecules(molInfo, resInfo, atomInfo, bondInfo, crdInfo):
    from SimpleSession import registerAttribute
    items = []
    sm = globals.sessionMap

    res2mol = []
    atom2mol = []
    for ids, name, cid, display, lineWidth, pointSize, stickScale, \
    pdbHeaders, surfaceOpacity, ballScale, vdwDensity, autochain, \
    ribbonHidesMainchain, riCID, aromaticCID, aromaticDisplay, \
    aromaticLineType, aromaticMode, hidden in zip(
       expandSummary(molInfo['ids']),
       expandSummary(molInfo['name']),
       expandSummary(molInfo['color']),
       expandSummary(molInfo['display']),
       expandSummary(molInfo['lineWidth']),
       expandSummary(molInfo['pointSize']),
       expandSummary(molInfo['stickScale']),
       molInfo['pdbHeaders'],
       expandSummary(molInfo['surfaceOpacity']),
       expandSummary(molInfo['ballScale']),
       expandSummary(molInfo['vdwDensity']),
       expandSummary(molInfo['autochain']),
       expandSummary(molInfo['ribbonHidesMainchain']),
       expandSummary(molInfo['ribbonInsideColor']),
       expandSummary(molInfo['aromaticColor']),
       expandSummary(molInfo['aromaticDisplay']),
       expandSummary(molInfo['aromaticLineType']),
       expandSummary(molInfo['aromaticMode']),
       expandSummary(molInfo['hidden'])
       ):
        m = chimera.Molecule()
        sm[len(items)] = m
        items.append(m)
        m.name = name
        from SimpleSession import modelMap, modelOffset
        chimera.openModels.add([m],
                               baseId=ids[0] + modelOffset,
                               subid=ids[1],
                               hidden=hidden)
        modelMap.setdefault(ids, []).append(m)
        m.color = getColor(cid)
        m.display = display
        m.lineWidth = lineWidth
        m.pointSize = pointSize
        m.stickScale = stickScale
        m.setAllPDBHeaders(pdbHeaders)
        m.surfaceOpacity = surfaceOpacity
        m.ballScale = ballScale
        m.vdwDensity = vdwDensity
        m.autochain = autochain
        m.ribbonHidesMainchain = ribbonHidesMainchain
        m.ribbonInsideColor = getColor(riCID)
        m.aromaticColor = getColor(aromaticCID)
        m.aromaticDisplay = aromaticDisplay
        m.aromaticLineType = aromaticLineType
        m.aromaticMode = aromaticMode
    if molInfo['optional']:
        for attrName, info in molInfo['optional'].items():
            hashable, sv = info
            registerAttribute(chimera.Molecule, attrName, hashable=hashable)
            vals = expandSummary(sv, hashable=hashable)
            for m, val in zip(items, vals):
                if val is not None:
                    setattr(m, attrName, val)

    resStart = len(items)
    for mid, name, chain, pos, insert, rcid, lcid, ss, ssId, ribbonDrawMode, \
    ribbonDisplay, label, labelOffset, isHet, fillDisplay, fillMode in zip(
       expandSummary(resInfo['molecule']),
       expandSummary(resInfo['name']),
       expandSummary(resInfo['chain']),
       expandSequentialSummary(resInfo['position']),
       expandSummary(resInfo['insert']),
       expandSummary(resInfo['ribbonColor']),
       expandSummary(resInfo['labelColor']),
       expandSummary(resInfo['ss']),
       expandSummary(resInfo['ssId']),
       expandSummary(resInfo['ribbonDrawMode']),
       expandSummary(resInfo['ribbonDisplay']),
       expandSummary(resInfo['label']),
       expandSummary(resInfo['labelOffset']),
       expandSummary(resInfo['isHet']),
       expandSummary(resInfo['fillDisplay']),
       expandSummary(resInfo['fillMode']),
       ):
        m = idLookup(mid)
        r = m.newResidue(name, chain, pos, insert)
        sm[len(items)] = r
        items.append(r)
        r.ribbonColor = getColor(rcid)
        r.labelColor = getColor(lcid)
        r.isHelix, r.isStrand, r.isTurn = ss
        r.ssId = ssId
        r.ribbonDrawMode = ribbonDrawMode
        r.ribbonDisplay = ribbonDisplay
        r.label = label
        if labelOffset is not None:
            r.labelOffset = labelOffset
        r.isHet = isHet
        r.fillDisplay = fillDisplay
        r.fillMode = fillMode
    if resInfo['optional']:
        residues = items[resStart:]
        for attrName, info in resInfo['optional'].items():
            hashable, sv = info
            registerAttribute(chimera.Residue, attrName, hashable=hashable)
            vals = expandSummary(sv, hashable=hashable)
            for r, val in zip(residues, vals):
                if val is not None:
                    setattr(r, attrName, val)

    atomStart = len(items)
    for rid, name, element, cid, vcid, lcid, scid, drawMode, display, \
    label, labelOffet, surfaceDisplay, surfaceCategory, surfaceOpacity, \
    radius, vdw, idatmType, altLoc in zip(
       expandSummary(atomInfo['residue']),
       expandSummary(atomInfo['name']),
       expandSummary(atomInfo['element']),
       expandSummary(atomInfo['color']),
       expandSummary(atomInfo['vdwColor']),
       expandSummary(atomInfo['labelColor']),
       expandSummary(atomInfo['surfaceColor']),
       expandSummary(atomInfo['drawMode']),
       expandSummary(atomInfo['display']),
       expandSummary(atomInfo['label']),
       expandSummary(atomInfo['labelOffset']),
       expandSummary(atomInfo['surfaceDisplay']),
       expandSummary(atomInfo['surfaceCategory']),
       expandSummary(atomInfo['surfaceOpacity']),
       expandSummary(atomInfo['radius']),
       expandSummary(atomInfo['vdw']),
       expandSummary(atomInfo['idatmType']),
       expandSummary(atomInfo['altLoc'])
       ):
        r = idLookup(rid)
        a = r.molecule.newAtom(name, chimera.Element(element))
        sm[len(items)] = a
        items.append(a)
        r.addAtom(a)
        a.color = getColor(cid)
        a.vdwColor = getColor(vcid)
        a.labelColor = getColor(lcid)
        a.surfaceColor = getColor(scid)
        a.drawMode = drawMode
        a.display = display
        a.label = label
        if labelOffset is not None:
            a.labelOffset = labelOffset
        a.surfaceDisplay = surfaceDisplay
        a.surfaceCategory = surfaceCategory
        a.surfaceOpacity = surfaceOpacity
        a.radius = radius
        a.vdw = vdw
        if idatmType:
            a.idatmType = idatmType
        a.altLoc = altLoc
    if atomInfo['optional']:
        atoms = items[atomStart:]
        for attrName, info in atomInfo['optional'].items():
            hashable, sv = info
            registerAttribute(chimera.Atom, attrName, hashable=hashable)
            vals = expandSummary(sv, hashable=hashable)
            for a, val in zip(atoms, vals):
                if val is not None:
                    setattr(a, attrName, val)

    bondStart = len(items)
    for atoms, drawMode, display, label, labelOffset, radius in zip(
            bondInfo['atoms'], expandSummary(bondInfo['drawMode']),
            expandSummary(bondInfo['display']),
            expandSummary(bondInfo['label']),
            expandSummary(bondInfo['labelOffset']),
            expandSummary(bondInfo['radius'])):
        a1, a2 = [idLookup(a) for a in atoms]
        b = a1.molecule.newBond(a1, a2)
        sm[len(items)] = b
        items.append(b)
        b.drawMode = drawMode
        b.display = display
        b.label = label
        if labelOffset is not None:
            b.labelOffset = labelOffset
        b.radius = radius
    if bondInfo.get('optional', {}):
        bonds = items[bondStart:]
        for attrName, info in bondInfo['optional'].items():
            hashable, sv = info
            registerAttribute(chimera.Bond, attrName, hashable=hashable)
            vals = expandSummary(sv, hashable=hashable)
            for b, val in zip(bonds, vals):
                if val is not None:
                    setattr(b, attrName, val)

    from chimera import Point
    for mid, crdSets in crdInfo.items():
        m = idLookup(mid)
        active = crdSets.pop('active')
        for key, crds in crdSets.items():
            coordSet = m.newCoordSet(key, len(crds))
            for aid, crdString in crds:
                idLookup(aid).setCoord(
                    Point(*tuple([float(c) for c in crdString.split()])),
                    coordSet)
            if key == active:
                m.activeCoordSet = coordSet
コード例 #16
0
ファイル: v45.py プロジェクト: davem22101/semanticscience
def restoreMolecules(molInfo, resInfo, atomInfo, bondInfo, crdInfo):
	from SimpleSession import registerAttribute
	items = []
	sm = globals.sessionMap

	res2mol = []
	atom2mol = []
	for ids, name, cid, display, lineWidth, pointSize, stickScale, \
	pdbHeaders, surfaceOpacity, ballScale, vdwDensity, autochain, \
	ribbonHidesMainchain, riCID, aromaticCID, aromaticDisplay, \
	aromaticLineType, aromaticMode, hidden in zip(
				expandSummary(molInfo['ids']),
				expandSummary(molInfo['name']),
				expandSummary(molInfo['color']),
				expandSummary(molInfo['display']),
				expandSummary(molInfo['lineWidth']),
				expandSummary(molInfo['pointSize']),
				expandSummary(molInfo['stickScale']),
				molInfo['pdbHeaders'],
				expandSummary(molInfo['surfaceOpacity']),
				expandSummary(molInfo['ballScale']),
				expandSummary(molInfo['vdwDensity']),
				expandSummary(molInfo['autochain']),
				expandSummary(molInfo['ribbonHidesMainchain']),
				expandSummary(molInfo['ribbonInsideColor']),
				expandSummary(molInfo['aromaticColor']),
				expandSummary(molInfo['aromaticDisplay']),
				expandSummary(molInfo['aromaticLineType']),
				expandSummary(molInfo['aromaticMode']),
				expandSummary(molInfo['hidden'])
				):
		m = chimera.Molecule()
		sm[len(items)] = m
		items.append(m)
		m.name = name
		from SimpleSession import modelMap, modelOffset
		chimera.openModels.add([m], baseId=ids[0]+modelOffset,
						subid=ids[1], hidden=hidden)
		modelMap.setdefault(ids, []).append(m)
		m.color = getColor(cid)
		m.display = display
		m.lineWidth = lineWidth
		m.pointSize = pointSize
		m.stickScale = stickScale
		m.setAllPDBHeaders(pdbHeaders)
		m.surfaceOpacity = surfaceOpacity
		m.ballScale = ballScale
		m.vdwDensity = vdwDensity
		m.autochain = autochain
		m.ribbonHidesMainchain = ribbonHidesMainchain
		m.ribbonInsideColor = getColor(riCID)
		m.aromaticColor = getColor(aromaticCID)
		m.aromaticDisplay = aromaticDisplay
		m.aromaticLineType = aromaticLineType
		m.aromaticMode = aromaticMode
	if molInfo['optional']:
		for attrName, info in molInfo['optional'].items():
			hashable, sv = info
			registerAttribute(chimera.Molecule, attrName,
							hashable=hashable)
			vals = expandSummary(sv, hashable=hashable)
			for m, val in zip(items, vals):
				if val is not None:
					setattr(m, attrName, val)

	resStart = len(items)
	for mid, name, chain, pos, insert, rcid, lcid, ss, ssId, ribbonDrawMode, \
	ribbonDisplay, label, labelOffset, isHet, fillDisplay, fillMode in zip(
				expandSummary(resInfo['molecule']),
				expandSummary(resInfo['name']),
				expandSummary(resInfo['chain']),
				expandSequentialSummary(resInfo['position']),
				expandSummary(resInfo['insert']),
				expandSummary(resInfo['ribbonColor']),
				expandSummary(resInfo['labelColor']),
				expandSummary(resInfo['ss']),
				expandSummary(resInfo['ssId']),
				expandSummary(resInfo['ribbonDrawMode']),
				expandSummary(resInfo['ribbonDisplay']),
				expandSummary(resInfo['label']),
				expandSummary(resInfo['labelOffset']),
				expandSummary(resInfo['isHet']),
				expandSummary(resInfo['fillDisplay']),
				expandSummary(resInfo['fillMode']),
				):
		m = idLookup(mid)
		r = m.newResidue(name, chain, pos, insert)
		sm[len(items)] = r
		items.append(r)
		r.ribbonColor = getColor(rcid)
		r.labelColor = getColor(lcid)
		r.isHelix, r.isStrand, r.isTurn = ss
		r.ssId = ssId
		r.ribbonDrawMode = ribbonDrawMode
		r.ribbonDisplay = ribbonDisplay
		r.label = label
		if labelOffset is not None:
			r.labelOffset = labelOffset
		r.isHet = isHet
		r.fillDisplay = fillDisplay
		r.fillMode = fillMode
	if resInfo['optional']:
		residues = items[resStart:]
		for attrName, info in resInfo['optional'].items():
			hashable, sv = info
			registerAttribute(chimera.Residue, attrName,
							hashable=hashable)
			vals = expandSummary(sv, hashable=hashable)
			for r, val in zip(residues, vals):
				if val is not None:
					setattr(r, attrName, val)

	atomStart = len(items)
	for rid, name, element, cid, vcid, lcid, scid, drawMode, display, \
	label, labelOffet, surfaceDisplay, surfaceCategory, surfaceOpacity, \
	radius, vdw, idatmType, altLoc in zip(
				expandSummary(atomInfo['residue']),
				expandSummary(atomInfo['name']),
				expandSummary(atomInfo['element']),
				expandSummary(atomInfo['color']),
				expandSummary(atomInfo['vdwColor']),
				expandSummary(atomInfo['labelColor']),
				expandSummary(atomInfo['surfaceColor']),
				expandSummary(atomInfo['drawMode']),
				expandSummary(atomInfo['display']),
				expandSummary(atomInfo['label']),
				expandSummary(atomInfo['labelOffset']),
				expandSummary(atomInfo['surfaceDisplay']),
				expandSummary(atomInfo['surfaceCategory']),
				expandSummary(atomInfo['surfaceOpacity']),
				expandSummary(atomInfo['radius']),
				expandSummary(atomInfo['vdw']),
				expandSummary(atomInfo['idatmType']),
				expandSummary(atomInfo['altLoc'])
				):
		r = idLookup(rid)
		a = r.molecule.newAtom(name, chimera.Element(element))
		sm[len(items)] = a
		items.append(a)
		r.addAtom(a)
		a.color = getColor(cid)
		a.vdwColor = getColor(vcid)
		a.labelColor = getColor(lcid)
		a.surfaceColor = getColor(scid)
		a.drawMode = drawMode
		a.display = display
		a.label = label
		if labelOffset is not None:
			a.labelOffset = labelOffset
		a.surfaceDisplay = surfaceDisplay
		a.surfaceCategory = surfaceCategory
		a.surfaceOpacity = surfaceOpacity
		a.radius = radius
		a.vdw = vdw
		if idatmType:
			a.idatmType = idatmType
		a.altLoc = altLoc
	if atomInfo['optional']:
		atoms = items[atomStart:]
		for attrName, info in atomInfo['optional'].items():
			hashable, sv = info
			registerAttribute(chimera.Atom, attrName,
							hashable=hashable)
			vals = expandSummary(sv, hashable=hashable)
			for a, val in zip(atoms, vals):
				if val is not None:
					setattr(a, attrName, val)

	bondStart = len(items)
	for atoms, drawMode, display, label, labelOffset, radius in zip(
					bondInfo['atoms'],
					expandSummary(bondInfo['drawMode']),
					expandSummary(bondInfo['display']),
					expandSummary(bondInfo['label']),
					expandSummary(bondInfo['labelOffset']),
					expandSummary(bondInfo['radius'])
					):
		a1, a2 = [idLookup(a) for a in atoms]
		b = a1.molecule.newBond(a1, a2)
		sm[len(items)] = b
		items.append(b)
		b.drawMode = drawMode
		b.display = display
		b.label = label
		if labelOffset is not None:
			b.labelOffset = labelOffset
		b.radius = radius
	if bondInfo.get('optional', {}):
		bonds = items[bondStart:]
		for attrName, info in bondInfo['optional'].items():
			hashable, sv = info
			registerAttribute(chimera.Bond, attrName,
							hashable=hashable)
			vals = expandSummary(sv, hashable=hashable)
			for b, val in zip(bonds, vals):
				if val is not None:
					setattr(b, attrName, val)

	from chimera import Point
	for mid, crdSets in crdInfo.items():
		m = idLookup(mid)
		active = crdSets.pop('active')
		for key, crds in crdSets.items():
			coordSet = m.newCoordSet(key, len(crds))
			for aid, crdString in crds:
				idLookup(aid).setCoord(Point(*tuple([float(c)
					for c in crdString.split()])), coordSet)
			if key == active:
				m.activeCoordSet = coordSet
コード例 #17
0
def restoreMolecules(molInfo, resInfo, atomInfo, bondInfo, crdInfo):
    items = []
    sm = globals.sessionMap

    res2mol = []
    atom2mol = []
    openModelsArgs = {}
    for ids, name, cid, display, lineWidth, pointSize, stickScale, \
    pdbHeaders, surfaceOpacity, ballScale, vdwDensity, autochain, \
    ribbonHidesMainchain in zip(
       expandSummary(molInfo['ids']),
       expandSummary(molInfo['name']),
       expandSummary(molInfo['color']),
       expandSummary(molInfo['display']),
       expandSummary(molInfo['lineWidth']),
       expandSummary(molInfo['pointSize']),
       expandSummary(molInfo['stickScale']),
       molInfo['pdbHeaders'],
       expandSummary(molInfo['surfaceOpacity']),
       expandSummary(molInfo['ballScale']),
       expandSummary(molInfo['vdwDensity']),
       expandSummary(molInfo['autochain']),
       expandSummary(molInfo['ribbonHidesMainchain'])
       ):
        m = chimera.Molecule()
        sm[len(items)] = m
        items.append(m)
        m.name = name
        from SimpleSession import modelMap, modelOffset
        chimera.openModels.add([m], baseId=ids[0] + modelOffset, subid=ids[1])
        modelMap.setdefault(ids, []).append(m)
        m.color = getColor(cid)
        m.display = display
        m.lineWidth = lineWidth
        m.pointSize = pointSize
        m.stickScale = stickScale
        m.setAllPDBHeaders(pdbHeaders)
        m.surfaceOpacity = surfaceOpacity
        m.ballScale = ballScale
        m.vdwDensity = vdwDensity
        m.autochain = autochain
        m.ribbonHidesMainchain = ribbonHidesMainchain

    for mid, name, chain, pos, insert, rcid, lcid, ss, ribbonDrawMode, \
    ribbonDisplay, label in zip(
       expandSummary(resInfo['molecule']),
       expandSummary(resInfo['name']),
       expandSummary(resInfo['chain']),
       resInfo['position'],
       expandSummary(resInfo['insert']),
       expandSummary(resInfo['ribbonColor']),
       expandSummary(resInfo['labelColor']),
       expandSummary(resInfo['ss']),
       expandSummary(resInfo['ribbonDrawMode']),
       expandSummary(resInfo['ribbonDisplay']),
       expandSummary(resInfo['label'])
       ):
        m = idLookup(mid)
        r = m.newResidue(name, chain, pos, insert)
        sm[len(items)] = r
        items.append(r)
        r.ribbonColor = getColor(rcid)
        r.labelColor = getColor(lcid)
        r.isHelix, r.isStrand, r.isTurn = ss
        r.ribbonDrawMode = ribbonDrawMode
        r.ribbonDisplay = ribbonDisplay
        r.label = label

    for rid, name, element, cid, vcid, lcid, scid, drawMode, display, \
    label, surfaceDisplay, surfaceCategory, surfaceOpacity, radius, vdw, \
    bfactor, occupancy, charge, idatmType in zip(
       expandSummary(atomInfo['residue']),
       expandSummary(atomInfo['name']),
       expandSummary(atomInfo['element']),
       expandSummary(atomInfo['color']),
       expandSummary(atomInfo['vdwColor']),
       expandSummary(atomInfo['labelColor']),
       expandSummary(atomInfo['surfaceColor']),
       expandSummary(atomInfo['drawMode']),
       expandSummary(atomInfo['display']),
       expandSummary(atomInfo['label']),
       expandSummary(atomInfo['surfaceDisplay']),
       expandSummary(atomInfo['surfaceCategory']),
       expandSummary(atomInfo['surfaceOpacity']),
       expandSummary(atomInfo['radius']),
       expandSummary(atomInfo['vdw']),
       expandSummary(atomInfo['bfactor']),
       expandSummary(atomInfo['occupancy']),
       expandSummary(atomInfo['charge']),
       expandSummary(atomInfo['idatmType'])
       ):
        r = idLookup(rid)
        a = r.molecule.newAtom(name, chimera.Element(element))
        sm[len(items)] = a
        items.append(a)
        r.addAtom(a)
        a.color = getColor(cid)
        a.vdwColor = getColor(vcid)
        a.labelColor = getColor(lcid)
        a.surfaceColor = getColor(scid)
        a.drawMode = drawMode
        a.display = display
        a.label = label
        a.surfaceDisplay = surfaceDisplay
        a.surfaceCategory = surfaceCategory
        a.surfaceOpacity = surfaceOpacity
        a.radius = radius
        a.vdw = vdw
        if bfactor is not None:
            a.bfactor = bfactor
        if occupancy is not None:
            a.occupancy = occupancy
        if charge is not None:
            a.charge = charge
        if idatmType:
            a.idatmType = idatmType

    for atoms, drawMode, display in zip(bondInfo['atoms'],
                                        expandSummary(bondInfo['drawMode']),
                                        expandSummary(bondInfo['display'])):
        a1, a2 = [idLookup(a) for a in atoms]
        b = a1.molecule.newBond(a1, a2)
        sm[len(items)] = b
        items.append(b)
        b.drawMode = drawMode
        b.display = display

    from chimera import Point
    for mid, crdSets in crdInfo.items():
        m = idLookup(mid)
        active = crdSets.pop('active')
        for key, crds in crdSets.items():
            coordSet = m.newCoordSet(key, len(crds))
            for aid, crdString in crds:
                idLookup(aid).setCoord(
                    Point(*tuple([float(c) for c in crdString.split()])),
                    coordSet)
            if key == active:
                m.activeCoordSet = coordSet