SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    Temperature color schemes

    Apps
    3
    12
    6457
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Piriziwè last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Stephane
        Stephane last edited by Stephane

        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
        P 2 Replies Last reply Reply Quote 1
        • P
          Piriziwè @Stephane last edited by

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

          1 Reply Last reply Reply Quote 0
          • Stephane
            Stephane last edited by Stephane

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

            P 1 Reply Last reply Reply Quote 0
            • P
              Piriziwè @Stephane last edited by

              @stephane-redon Thank you

              1 Reply Last reply Reply Quote 0
              • DmitriyMarin
                DmitriyMarin last edited by DmitriyMarin

                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,
                The SAMSON Team, https://s-c.io

                P 1 Reply Last reply Reply Quote 0
                • P
                  Piriziwè @DmitriyMarin last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • P
                    Piriziwè @Stephane last edited by

                    @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?

                    P 1 Reply Last reply Reply Quote 0
                    • P
                      Piriziwè @Piriziwè last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • Stephane
                        Stephane last edited by

                        Sorry, should have mentioned that. Great!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post