Temperature color schemes



  • I would like to set atoms' colors according to the value of their temperature factor. I found a picture (in attached) during my research on this situation. I would like to know if it is possible to be done? If so, would you mind helping me with some guidance, please?!



  • Yes, it is possible. For that you should choose the molecule in the Document view, and then choose in the properties menu Set color -> Per attribute -> Temperature factor



  • Thank you, Sir. Sorry for not precising in my post. I would like to do it programmatically. By code, I load a pdb or xyz file and then color atoms according to their temperature factor.



  • Here is essentially the code we use in SAMSON when the user does what @Dmitriy-Marin suggested:

    
    // index the current selection 
    
    SBPointerIndexer<SBNode> const* selectedNodes = SAMSON::getActiveDocument()->getSelectedNodes();
    
    SBNodeIndexer nodeIndexer;
    SB_FOR(SBNode* node, *selectedNodes) nodeIndexer.addNode(node);
    
    // make the color change undoable (start holding changes to the document)
    
    SAMSON::beginHolding("Color per temperature factor");
    
    // remove existing materials from selected nodes and their descendants
    
    SB_FOR(SBNode* node, *selectedNodes) {
    
        SBNodeIndexer nodeIndexer;
        node->getNodes(nodeIndexer);
    
        SB_FOR(SBNode* descendantNode, nodeIndexer) descendantNode->removeMaterial();
    
    }
    
    // apply the new color scheme 
    
    SB_FOR(SBNode* node, *selectedNodes) {
    
        SBNodeMaterial* nodeMaterial = new SBNodeMaterial();
        if (!node->addMaterial(nodeMaterial)) delete nodeMaterial;
    
        SBNodeColorScheme* colorScheme = new SBDColorSchemePerTemperatureFactor(nodeIndexer);
        node->getMaterial()->setColorScheme(colorScheme);
    
    }
    
    // stop holding changes to the document
    
    SAMSON::endHolding();
    

    The reason we index the current selection in nodeIndexer (which is passed to the color scheme) is
    so that the color scheme can traverse these nodes, and their descendants, and determine the minimum and maximum values of the temperature factor.

    Other color schemes are usable:

    • SBDColorSchemeConstant
    • SBDColorSchemeCPK
    • SBDColorSchemePerChainID
    • SBDColorSchemePerFormalCharge
    • SBDColorSchemePerOccupancy
    • SBDColorSchemePerPartialCharge
    • SBDColorSchemePerResidueSequenceNumber
    • SBDColorSchemePerResidueType
    • SBDColorSchemePerSecondaryStructureType


  • @stephane-redon Thank you very much. I am going to try it and give you a feedback about the experience.



  • By the way, sorry, I just fixed the code above (replaced Core and Data with SAMSON) (thanks @Dmitriy-Marin !)



  • @stephane-redon Thank you



  • If you want a custom colorization according to the temperature factor, you can use the same algorithm which @Stephane-Redon showed above and colorize atoms according to the node->getTemperatureFactor() using your own color scheme:

    float red = node->getTemperatureFactor() / maximalTemperatureFactor; // should be scaled to 1.0
    SBDColorSchemeConstant *colorScheme = new SBDColorSchemeConstant(red, 0.0, 0.0, 1.0); //SBDColorSchemeConstant (float red, float green, float blue, float alpha=1.0f)
    node->getMaterial()->setColorScheme(colorScheme);
    

    You can create more advanced color scheme by setting the HSV color space based on the temperatureFactor and converting it to the RGB color space.



  • @dmitriy-marin Thank you very much. That's great !



  • @stephane-redon Hi Sir,
    I am trying the example above and I have an error when I compile: error: expected type-specifier before ‘SBDColorSchemePerTemperatureFactor’
    SBNodeColorScheme* colorScheme = new SBDColorSchemePerTemperatureFactor(nodeIndexer);

    Would you mind helping me with this error, please?



  • @piriziwè It's done. I just included "SBDColorSchemePerTemperatureFactor.hpp"



  • Sorry, should have mentioned that. Great!


Log in to reply
 

Looks like your connection to SAMSON Connect - Forum was lost, please wait while we try to reconnect.