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

    Getting atoms inside a .stl object

    Brainstorm
    2
    10
    96
    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.
    • T
      Tom 1 last edited by

      SAMSON_stl.PNG

      I was wondering if it was possible to use a .stl object to carve crystals in SAMSON. I've been trying out different python snippets provided by the AI assistant which seem like they are just on the verge of doing it, but ultimately are missing some capability I can't quite find a way to add. SAMSON_STL.sam

      The idea is it you could position a solid mesh object on your crystal model, do some a test to see if an atom is inside the mesh, and then delete that atom. For simple meshes the test could be if it is inside the bounding box of the mesh.

      This could be a cool feature. SAMSON file attached of the system in the image.

      Thanks,

      Tom

      1 Reply Last reply Reply Quote 0
      • T
        Tom 1 last edited by

        I went back and tried to open the file I uploaded here and I get an error that it can't be loaded. Maybe .stls cannot be saved in a .sam?

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

          Hi Tom, it might be possible to use some computational geometry libraries that would determine whether a point in inside a triangulated object (it's non trivial for non-convex objects, but they can often be decomposed into convex parts). I'll look into the serialization of the STL objects but I don't immediately see any issues.

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

            This one might help: https://github.com/quant-sci/compute-geometry. If you have a convex object like the one in the image, I guess you'd first compute its convex hull thanks to this library, and you'd then use the resulting convex hull to determine whether an atom is inside or not.

            1 Reply Last reply Reply Quote 1
            • T
              Tom 1 last edited by

              Thanks for the replies and guidance. I was looking at a couple external libraries to work with stls. I got stuck because I couldn't find anyway to access the stl object through the SAMSON python api then I found Mesh = NodeType.VisualModelMesh? I will work on it again.

              1 Reply Last reply Reply Quote 0
              • T
                Tom 1 last edited by

                I think I meant"
                from samson import SBNode # in the embedded console it's already imported
                Mesh = SBNode.Type.Mesh # or: Mesh = SBNode.Mesh

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

                  The STL importer is actually creating an object of its own class, and cannot be manipulated like a mesh. I'm going to modify that importer so it produces meshes instead. At the moment, you can import obj files instead. However, we also need to expose surfaces in python (meshes are collections of surfaces), which are the classes which expose the underlying vertices and triangles. Without this, you will not be able to do the geometry tests in python (the API is available in C++ though, see https://documentation.samson-connect.net/developers/latest/api/classSBMVisualModelSurface/)

                  1 Reply Last reply Reply Quote 1
                  • T
                    Tom 1 last edited by

                    Thank you for the tremendous help!

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

                      I've updated the STL importer. Opening a STL object into SAMSON will now create meshes instead of the previous type of objects (but loading your previous files should work again and will create the previous type of objects, I was able to import your file). The benefit of meshes is that they're the standard way to have triangulated geometry in SAMSON, and you can move them, rotate them, align them, etc. (and we'll expose the underlying surfaces in Python so we can do geometry tests). The update will be available with SAMSON 2026 R1, which should arrive very soon now.

                      1 Reply Last reply Reply Quote 1
                      • T
                        Tom 1 last edited by

                        That's awesome! I can't wait to try it out. In addition to the crystal carver project, I've done experiments connecting mesh objects and updating them in near real-time from molecular dynamics data. You can see an example here: https://www.youtube.com/watch?v=vMpnWHdG2Ds I actually have a good use case for this. I wonder if anyone else does? Also in the future SAMSON could be used for systems that span from quantum modeling through classical molecular dynamics and into rigid-body-FEA-Multiphysics simulations. I am not aware of any other platform that can do that.

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