Skip to content
0
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. Apps
  4. Temperature color schemes

Temperature color schemes

Scheduled Pinned Locked Moved Apps
12 Posts 3 Posters 10.1k Views
  • 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
    P
    Piriziwè
    wrote on last edited by
    #3

    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
    0
    • StephaneS
      StephaneS
      Stephane
      wrote on last edited by Stephane
      #4

      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
      1
      • StephaneS 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
        P
        Piriziwè
        wrote on last edited by
        #5

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

        1 Reply Last reply
        0
        • StephaneS
          StephaneS
          Stephane
          wrote on last edited by Stephane
          #6

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

          P 1 Reply Last reply
          0
          • StephaneS Stephane

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

            P
            P
            Piriziwè
            wrote on last edited by
            #7

            @stephane-redon Thank you

            1 Reply Last reply
            0
            • DmitriyMarinD
              DmitriyMarinD
              DmitriyMarin
              wrote on last edited by DmitriyMarin
              #8

              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
              0
              • DmitriyMarinD 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.

                P
                P
                Piriziwè
                wrote on last edited by
                #9

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

                1 Reply Last reply
                0
                • StephaneS 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
                  P
                  Piriziwè
                  wrote on last edited by
                  #10

                  @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
                  0
                  • P Piriziwè

                    @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
                    P
                    Piriziwè
                    wrote on last edited by
                    #11

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

                    1 Reply Last reply
                    0
                    • StephaneS
                      StephaneS
                      Stephane
                      wrote on last edited by
                      #12

                      Sorry, should have mentioned that. Great!

                      1 Reply Last reply
                      0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post