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

    Usage of existing elements created by someone else

    Simulation
    2
    4
    2894
    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.
    • A
      Andrii last edited by

      Hello!

      Can we use in the state updater element functionality of existing SAMSON elements?

      We want to use in our element functionality of TWISTER element. Is it possible somehow specify in our code control points for Twister and move points to twist molecule?

      Thanks

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

        Hello @Andrii

        Brief answers to the two questions: 1) Yes; 2) No, not for now.

        The answer to the 1st question. Yes, you can use the functionality of existing SAMSON Elements in your Element, but only the functionality which is exposed. Please, check SAMSON Introspection mechanism (note, that some parts of the introspection functionality described in the documentation have been updated and not yet modified in the documentation).

        Let's say you want to use the functionality of a class called SEMyClass from the SAMSON Element with UUID 554FEFC0-CF52-A7EC-BEBB-3230C5705738. It can be done like this:

        // Create a class proxy
        SBProxy* classProxy = SAMSON::getProxy("SEMyClass", SBUUID("554FEFC0-CF52-A7EC-BEBB-3230C5705738"));
        // Create an instance of the class
        SBValue objectHolder = classProxy->createInstance();
        

        Now you can use the exposed functionality of this class. Let's say the exposed class has an exposed function called multiply which multiplies two arguments. This function can be called like this:

        SBValue resultHolder = classProxy->call(objectHolder, "multiply", 10.0, 3.14);
        double result = SB_CAST<double>(resultHolder);
        

        The answer to the 2nd question. For now, it is not possible to use the Twister functionality in the code, because its functionality is not exposed. It might be updated in the next version.

        Dmitriy,
        The SAMSON Team, https://s-c.io

        1 Reply Last reply Reply Quote 1
        • A
          Andrii last edited by

          @DMITRIY MARIN, thank you!

          Could you please advise how find exposed functionality of existing SAMSON Elements?

          Thanks again

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

            @Andrii It can be done from the code. For now, we do not have docs/help web-pages for each of the SAMSON Elements, but it is in our plans to have them generated automatically for the exposed functionality.

            To get UUID and the class name of an Element from which you want to use functionality, you can open the Log (Edit menu -> Show log), then you can search for the Element and check its UUID and the class name:
            0_1541585623122_LogViewer-CheckUUIDAndNameOfSAMSONElement.png

            Now, in your code, you can do the following to print the exposed functionality of the Element:

            // Create a class proxy
            SBProxy* classProxy = SAMSON::getProxy("PDBDownload", SBUUID("6F5D45C5-E76E-CDC8-52D5-D2821C128BE8"));
            // Print class constructors
            classProxy->print();
            // Prints the interface
            classProxy->getInterface()->print();
            

            It will print the exposed functionality (constructor factory, interface functions, attributes) in the terminal (std::cout stream), like this:

            Class proxy:
            	Name	:PDBDownload
            	UUID	:23E5619D-CF88-CD8D-C516-725286102AF8
            	Element	:PDBDownload
            	Type	:10
            	Factory: 
            		PDBDownload()
            
            	Interface:
            		download(std::string, std::string)
            		downloadPdb(std::string)
            		downloadPdb1(std::string)
            
            	Attributes:
            

            You might need to allow the terminal with "--logconsole" flag when running SAMSON.

            If you have some problems with std::cout not printing to your terminal, you might print it yourself into std::cerr:

            // Print interface
            std::cerr << "Interface:\n";
            auto functionMap = classProxy->getInterface()->getFunctionMap();
            for (auto i = functionMap.begin(); i != functionMap.end(); ++i)
            	std::cerr << i->getKey() << "\n";
            
            // Print attributes
            std::cerr << "Attributes:\n";
            auto attributeMap = classProxy->getInterface()->getAttributeMap();
            for (auto i = attributeMap.begin(); i != attributeMap.end(); ++i)
            	std::cerr << i->getKey() << "\n";
            

            Dmitriy,
            The SAMSON Team, https://s-c.io

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