How to draw a circle with pcell rather than polygon points?

How to draw a circle with pcell rather than polygon points? I can realize it in klayout software by drawing a box and convert to pcell, but i don not know the which function I can use to realize directly in python.
And I wonder the different between pcell method and polygon points method.

Comments

  • Hello,

    Here's some Ruby code to insert the "CIRCLE" pcell from the "Basic" Library... It should be easy to convert to Python...

    module MyMacro
    
      include RBA
    
      layout_view = Application.instance.main_window.current_view
    
      layout = layout_view.active_cellview.layout
    
      viewed_cell = layout_view.active_cellview.cell
    
    # Create "CIRCLE" PCell
    #--------------------------
    
            lib = Library.library_by_name("Basic")
    
            lib || raise("Unknown lib 'Basic'")
    
            pcell_decl = lib.layout.pcell_declaration("CIRCLE")
    
            pcell_decl || raise("Unknown PCell 'CIRCLE'")
    
            param = { "layer" => LayerInfo.new(1, 0), "npoints" => 40, "actual_radius" => 5.0 }
    
            pv = pcell_decl.get_parameters.collect do |p|
    
                param[p.name] || p.default
    
            end # collect
    
            pcell_var = layout.add_pcell_variant(lib, pcell_decl.id, pv)
    
            transformation = DTrans.new(DPoint.new(0.0, 30.0))
    
            viewed_cell.insert(DCellInstArray.new(pcell_var, transformation))
    
    end # MyMacro
    

    A pcell has the advantage that it is easier to change afterwards by selecting the pcell instance and changing the properties (PCell parameters)...

    Cheers,

    Tomas

  • Adding on to Tomas - here is a link to a ruby pCell circle sample if you want to see the implementation and methods used:
    https://klayout.de/doc/programming/ruby_pcells.html

  • edited September 25

    Very good, thanks for the pointers :)

    However, I wonder if there is any advantage placing a PCell. A PCell is just a very complicated way to generate layout.

    The easiest way to generate a circle polygon in a Python script is using Polygon#ellipse (https://www.klayout.de/doc-qt5/code/class_Polygon.html#k_42). You give it a box, and this method will create a Polygon object with an ellipse (or circle for a square box) filling the box.

    Matthias

  • There is no such thing as a true circle in a Cartesian
    step-grid system. It's all vectors or pixels and not the
    ideal.

    I always up the vertex-count on drawn circular features
    using the primitive. Kinda fond of 72 as it's got so many
    clean-symmetry divisors.

  • Thanks all! And the code above works.
    I initially wanted to use pcell because the shapes got from polygons showed a difference between the diameters of their incircles and circumcircles. So I thought pcell might be a better way to go. Now I’ve figured out that, for my use case, incircle is correct.
    Pcell is more complicated than I expected, I would keep using polygon method.

  • I agree that PCell instantiation in scripts is quite complicated or bulky, especially for ellipses/texts for which dedicated classes/methods are available. However, if you have some (custom made) PCells available you can wrap the code above in a function, and then you need only one line of code in your script to instantiate a PCell, something like:

    def create_pcell_instance(pcellibrary, pcellname, pcellparameters, origin, orientation)
    
       ...
    
    end # def
    

    and in the script:

    create_pcell_instance("basic", "CIRCLE", { "layer" => LayerInfo.new(1, 0), "npoints" => 40, "actual_radius" => 5.0 }, [0.0, 30.0], "R0")

    Cheers,

    Tomas

Sign In or Register to comment.