Skip to content
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. A list of useful Sim4Life Python API snippets in a real project

A list of useful Sim4Life Python API snippets in a real project

Scheduled Pinned Locked Moved Python API
5 Posts 3 Posters 1.4k Views 3 Watching
  • 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.
  • Robin WydaegheR Offline
    Robin WydaegheR Offline
    Robin Wydaeghe
    wrote on last edited by
    #1

    Hello there,

    I made a coding project where I used the Sim4Life Python API quite a bit, check it out! I figured that a list of all the places it interfaces Sim4Life would be useful to the community: https://rwydaegh.github.io/goliat/reference/useful_s4l_snippets/

    Pasting only the questions here so Google crawlers can find it, while keeping this post not too long!

    1. Application control
    
    How can I start the Sim4Life application programmatically?
    
    How can I suppress Sim4Life logging output?
    
    2. Project management
    
    How can I create a new Sim4Life project?
    
    How can I open an existing Sim4Life project file?
    
    How can I save a Sim4Life project?
    
    How can I close a Sim4Life project?
    
    How can I get the current project file path?
    
    How can I access all simulations in a project?
    
    3. Model and geometry
    
    How can I get all entities in the model?
    
    How can I get the bounding box of entities?
    
    How can I create geometric entities?
    
    How can I import models from files?
    
    How can I export entities to files?
    
    How can I transform entities (translate, rotate, scale)?
    
    How can I calculate distance between entities?
    
    How can I delete entities?
    
    How can I create Vec3 vectors?
    
    How can I identify and work with entity groups?
    
    How can I access child entities in a group?
    
    How can I decompose a transform into rotation and translation?
    
    4. Materials
    
    How can I access the material database?
    
    How can I link a material from the database to a simulation?
    
    How can I access material properties?
    
    How can I update material properties after frequency changes?
    
    5. Simulation setup
    
    How can I create an EM-FDTD simulation?
    
    How can I configure solver settings (kernel, etc.)?
    
    How can I set simulation time and termination criteria?
    
    How can I add an edge source (antenna excitation)?
    
    How can I add a plane wave source (far-field)?
    
    How can I add sensors (edge, point, far-field)?
    
    How can I configure automatic gridding?
    
    How can I configure manual gridding?
    
    How can I configure subgridding?
    
    How can I configure grid padding?
    
    How can I configure boundary conditions (PML)?
    
    How can I add voxeler settings and create voxels?
    
    6. Simulation execution
    
    How can I write the solver input file?
    
    How can I run a simulation locally?
    
    How can I run iSolve.exe manually?
    
    How can I submit a simulation to oSPARC cloud?
    
    How can I get the input file name from a simulation?
    
    7. Results extraction
    
    How can I access simulation results?
    
    How can I use E-field data as input to analysis algorithms?
    
    How can I extract SAR statistics?
    
    How can I extract peak SAR location details?
    
    How can I extract input power?
    
    How can I extract power balance?
    
    How can I extract point sensor data?
    
    8. Data and downloads
    
    How can I get available model downloads?
    
    How can I download a model?
    
    9. Analysis algorithms
    
    How can I add an algorithm to the document?
    
    How can I remove an algorithm from the document?
    
    How can I access algorithm outputs?
    
    How can I access all simulation settings?
    
    How can I set frequency extraction settings?
    
    10. Rendering and UI
    
    How can I set the view direction?
    
    How can I zoom to an entity?
    
    How can I capture a screenshot?
    
    How can I change the current UI mode?
    
    How can I control entity visibility?
    

    The introduction of the full PythonAPIReference that ships with Sim4Life v8.2+ was a big help and I invite you to look there, or to use the To Python function. The tutorials also cover a lot, but I hope that these snippets can cover some of the leftover gaps when it comes to real-world examples.

    Feel free to contact me if there are mistakes, or open an issue. Happy coding!

    1 Reply Last reply
    2
    • brynB Offline
      brynB Offline
      bryn
      ZMT
      wrote on last edited by
      #2

      This is nice. Thanks @Robin-Wydaeghe

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rtc
        wrote on last edited by
        #3

        Hi @Robin-Wydaeghe, any chance you would be able to make this public again? Would greatly appreciate it to learn how to best calculate distance between 2 entities.

        1 Reply Last reply
        0
        • Robin WydaegheR Offline
          Robin WydaegheR Offline
          Robin Wydaeghe
          wrote on last edited by Robin Wydaeghe
          #4

          Hi @rtc
          The project has to undergo a temporary embargo as part of a publication which should finish hopefully in a couple months. For now, I've put the useful Sim4Life snippets in a gist here: https://gist.github.com/rwydaegh/aa87c8f76715786d99373ad9d0ba2f8b

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rtc
            wrote on last edited by
            #5

            thanks so much, appreciate it!

            1 Reply Last reply
            1

            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

            • Don't have an account? Register

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