Merge pull request #110 from mabrains/ic_connections_update

Updating devices connections for IC
diff --git a/IC/klayout/lvs/rule_decks/bjt_connection.lvs b/IC/klayout/lvs/rule_decks/bjt_connection.lvs
new file mode 100644
index 0000000..5e21220
--- /dev/null
+++ b/IC/klayout/lvs/rule_decks/bjt_connection.lvs
@@ -0,0 +1,68 @@
+################################################################################################
+# Copyright 2022 GlobalFoundries PDK Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################################
+
+#================================
+# ------ BJT CONNECTIONS --------
+#================================
+logger.info('Starting LVS BJT CONNECTIONS')
+
+# ==============
+# ---- vnpn ----
+# ==============
+
+# npn_02p00x02p00 nodes connections
+connect(npn_02p00x02p00_e, contact)
+connect(npn_02p00x02p00_b, contact)
+connect(npn_02p00x02p00_c, contact)
+
+# npn_05p00x05p00 nodes connections
+connect(npn_05p00x05p00_e, contact)
+connect(npn_05p00x05p00_b, contact)
+connect(npn_05p00x05p00_c, contact)
+
+# ==============
+# ---- vpnp ----
+# ==============
+
+# pnp_10p00x10p00 nodes connections
+connect(pnp_10p00x10p00_e, contact)
+connect(pnp_10p00x10p00_b, contact)
+connect(pnp_10p00x10p00_c, contact)
+
+# pnp_05p00x05p00 nodes connections
+connect(pnp_05p00x05p00_e, contact)
+connect(pnp_05p00x05p00_b, contact)
+connect(pnp_05p00x05p00_c, contact)
+
+# pnp_05p00x00p42 nodes connections
+connect(pnp_05p00x00p42_e, contact)
+connect(pnp_05p00x00p42_b, contact)
+connect(pnp_05p00x00p42_c, contact)
+
+# pnp_1p2x2p5 nodes connections
+connect(pnp_1p2x2p5_e, contact)
+connect(pnp_1p2x2p5_b, contact)
+connect(pnp_1p2x2p5_c, contact)
+
+# pnp_00p46x1p2 nodes connections
+connect(pnp_00p46x1p2_e, contact)
+connect(pnp_00p46x1p2_b, contact)
+connect(pnp_00p46x1p2_c, contact)
+
+# pnp_00p46x00p46 nodes connections
+connect(pnp_00p46x00p46_e, contact)
+connect(pnp_00p46x00p46_b, contact)
+connect(pnp_00p46x00p46_c, contact)
\ No newline at end of file
diff --git a/IC/klayout/lvs/rule_decks/devices_connections.lvs b/IC/klayout/lvs/rule_decks/devices_connections.lvs
index 7848e93..d4f6b9d 100644
--- a/IC/klayout/lvs/rule_decks/devices_connections.lvs
+++ b/IC/klayout/lvs/rule_decks/devices_connections.lvs
@@ -40,19 +40,27 @@
 connect(poly2_con, contact)
 connect(contact, metal1)
 connect(metal1, via1)
-connect(via1, metal2_ncap)
+connect(via1, metal2)
 if METAL_LEVEL != '2LM'
-  connect(metal2_ncap, via2)
-  connect(via2, metal3_ncap)
+  connect(metal2, via2_ncap)
+  connect(via2_ncap, metal3)
+  connect(via2_cap, fusetop)
+  connect(via2_cap, fusetop2)
   if METAL_LEVEL != '3LM'
-    connect(metal3_ncap, via3)
-    connect(via3, metal4_ncap)
+    connect(metal3, via3_ncap)
+    connect(via3_ncap, metal4)
+    connect(via3_cap, fusetop)
+    connect(via3_cap, fusetop2)
     if METAL_LEVEL != '4LM'
-      connect(metal4_ncap, via4)
-      connect(via4, metal5_ncap)
+      connect(metal4, via4_ncap)
+      connect(via4_ncap, metal5)
+      connect(via4_cap, fusetop)
+      connect(via4_cap, fusetop2)
       if METAL_LEVEL != '5LM'
-        connect(metal5_ncap, via5)
-        connect(via5, metaltop)
+        connect(metal5, via5_ncap)
+        connect(via5_ncap, metaltop)
+        connect(via5_cap, fusetop)
+        connect(via5_cap, fusetop2)
       end
     end
   end
@@ -64,13 +72,13 @@
 connect(comp, comp_label)
 connect(poly2_con, poly2_label)
 connect(metal1, metal1_label)
-connect(metal2_ncap, metal2_label)
+connect(metal2, metal2_label)
 if METAL_LEVEL != '2LM'
-  connect(metal3_ncap, metal3_label)
+  connect(metal3, metal3_label)
   if METAL_LEVEL != '3LM'
-    connect(metal4_ncap, metal4_label)
+    connect(metal4, metal4_label)
     if METAL_LEVEL != '4LM'
-      connect(metal5_ncap, metal5_label)
+      connect(metal5, metal5_label)
       connect(metaltop, metaltop_label) if METAL_LEVEL != '5LM'
     end
   end
@@ -90,131 +98,29 @@
 #================================
 # ------ BJT CONNECTIONS --------
 #================================
-logger.info('Starting LVS BJT CONNECTIONS')
 
-# ==============
-# ---- vnpn ----
-# ==============
-
-# npn_02p00x02p00 nodes connections
-connect(npn_02p00x02p00_e, contact)
-connect(npn_02p00x02p00_b, contact)
-connect(npn_02p00x02p00_c, contact)
-
-# npn_05p00x05p00 nodes connections
-connect(npn_05p00x05p00_e, contact)
-connect(npn_05p00x05p00_b, contact)
-connect(npn_05p00x05p00_c, contact)
-
-# ==============
-# ---- vpnp ----
-# ==============
-
-# pnp_10p00x10p00 nodes connections
-connect(pnp_10p00x10p00_e, contact)
-connect(pnp_10p00x10p00_b, contact)
-connect(pnp_10p00x10p00_c, contact)
-
-# pnp_05p00x05p00 nodes connections
-connect(pnp_05p00x05p00_e, contact)
-connect(pnp_05p00x05p00_b, contact)
-connect(pnp_05p00x05p00_c, contact)
-
-# pnp_05p00x00p42 nodes connections
-connect(pnp_05p00x00p42_e, contact)
-connect(pnp_05p00x00p42_b, contact)
-connect(pnp_05p00x00p42_c, contact)
-
-# pnp_1p2x2p5 nodes connections
-connect(pnp_1p2x2p5_e, contact)
-connect(pnp_1p2x2p5_b, contact)
-connect(pnp_1p2x2p5_c, contact)
-
-# pnp_00p46x1p2 nodes connections
-connect(pnp_00p46x1p2_e, contact)
-connect(pnp_00p46x1p2_b, contact)
-connect(pnp_00p46x1p2_c, contact)
-
-# pnp_00p46x00p46 nodes connections
-connect(pnp_00p46x00p46_e, contact)
-connect(pnp_00p46x00p46_b, contact)
-connect(pnp_00p46x00p46_c, contact)
-
+# %include bjt_connection.lvs
 
 #================================
 # ----- DIODE CONNECTIONS -------
 #================================
 
-logger.info('Starting LVS DIODE CONNECTIONS')
-
-# diode_np_1p8 
-connect(diode_np_1p8_terminal_n, contact)
-connect(diode_np_1p8_terminal_p, contact)
-
-# diode_pn_1p8
-connect(diode_pn_1p8_terminal_n, contact)
-connect(diode_pn_1p8_terminal_p, contact)
-
-# diode_np_3p3 
-connect(diode_np_3p3_terminal_n, contact)
-connect(diode_np_3p3_terminal_p, contact)
-
-# diode_pn_3p3
-connect(diode_pn_3p3_terminal_n, contact)
-connect(diode_pn_3p3_terminal_p, contact)
-
-# diode_nwp
-connect(diode_nwp_terminal_n, contact)
-connect(diode_nwp_terminal_p, contact)
-
-# diode_np_1p8_nat 
-connect(diode_np_1p8_nat_terminal_n, contact)
-connect(diode_np_1p8_nat_terminal_p, contact)
-
-# diode_np_3p3_nat
-connect(diode_np_3p3_nat_terminal_n, contact)
-connect(diode_np_3p3_nat_terminal_p, contact)
-
-# diode_dnwpw
-connect(diode_dnwps_terminal_p, contact)
-
-# diode_dnwps
-connect(diode_dnwps_terminal_p, contact)
-
+# %include diode_connection.lvs
 
 #==================================
 # ------ MIMCAP CONNECTIONS -------
 #==================================
 
-logger.info('Starting LVS MIMCAP CONNECTIONS')
-
-case MIM_OPTION
-when 'A'
-  connect(metal2, mim_virtual)
-  connect(fuse_cap, via2)
-
-when 'B'
-  connect(topmin1_metal, mimtm_virtual)
-  connect(fuse_cap, top_via)
-  connect(topmin1_metal, mimtm_stack1_virtual)
-  connect(topmin2_metal, mimtm_stack2_virtual)
-  connect(fuse2_cap, topmin1_via)
-end
+# %include mimcap_connection.lvs
 
 #========================================
 # ------ PN Varactors CONNECTIONS -------
 #========================================
 
-# pnvar_1p8 varactor nodes connections
-connect(pnvar_1p8_terminal_n, contact)
-connect(pnvar_1p8_terminal_p, contact)
-
+# %include pn_varactor_connection.lvs
 
 #================================
 # ---- RESISTOR DERIVATIONS -----
 #================================
 
-logger.info('Starting LVS RESISTOR CONNECTIONS')
-
-connect(nplus_cont, contact)
-connect(pplus_cont, contact)
\ No newline at end of file
+# %include res_connection.lvs
\ No newline at end of file
diff --git a/IC/klayout/lvs/rule_decks/diode_connection.lvs b/IC/klayout/lvs/rule_decks/diode_connection.lvs
new file mode 100644
index 0000000..2bd1560
--- /dev/null
+++ b/IC/klayout/lvs/rule_decks/diode_connection.lvs
@@ -0,0 +1,55 @@
+################################################################################################
+# Copyright 2022 GlobalFoundries PDK Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################################
+
+#================================
+# ----- DIODE CONNECTIONS -------
+#================================
+
+logger.info('Starting LVS DIODE CONNECTIONS')
+
+# diode_np_1p8 
+connect(diode_np_1p8_terminal_n, contact)
+connect(diode_np_1p8_terminal_p, contact)
+
+# diode_pn_1p8
+connect(diode_pn_1p8_terminal_n, contact)
+connect(diode_pn_1p8_terminal_p, contact)
+
+# diode_np_3p3 
+connect(diode_np_3p3_terminal_n, contact)
+connect(diode_np_3p3_terminal_p, contact)
+
+# diode_pn_3p3
+connect(diode_pn_3p3_terminal_n, contact)
+connect(diode_pn_3p3_terminal_p, contact)
+
+# diode_nwp
+connect(diode_nwp_terminal_n, contact)
+connect(diode_nwp_terminal_p, contact)
+
+# diode_np_1p8_nat 
+connect(diode_np_1p8_nat_terminal_n, contact)
+connect(diode_np_1p8_nat_terminal_p, contact)
+
+# diode_np_3p3_nat
+connect(diode_np_3p3_nat_terminal_n, contact)
+connect(diode_np_3p3_nat_terminal_p, contact)
+
+# diode_dnwpw
+connect(diode_dnwps_terminal_p, contact)
+
+# diode_dnwps
+connect(diode_dnwps_terminal_p, contact)
\ No newline at end of file
diff --git a/IC/klayout/lvs/rule_decks/general_derivations.lvs b/IC/klayout/lvs/rule_decks/general_derivations.lvs
index 3ab99e9..efd371d 100644
--- a/IC/klayout/lvs/rule_decks/general_derivations.lvs
+++ b/IC/klayout/lvs/rule_decks/general_derivations.lvs
@@ -39,3 +39,24 @@
 psd_dw          = pcomp.and(dnwell).interacting(pgate).not(pgate).not(res_mk)
 nwell_con       = nwell.not(res_mk)
 poly2_con       = poly2.not(res_mk).not(plfuse)
+
+
+# Splitting vias into cap-vias, ncap-vias
+
+if METAL_LEVEL != '2LM'
+  via2_ncap = via2.not(fusetop.or(fusetop2))
+  via2_cap  = via2.and(fusetop.or(fusetop2))
+  if METAL_LEVEL != '3LM'
+    via3_ncap = via3.not(fusetop.or(fusetop2))
+    via3_cap  = via3.and(fusetop.or(fusetop2))
+    if METAL_LEVEL != '4LM'
+      via4_ncap = via4.not(fusetop.or(fusetop2))
+      via4_cap  = via4.and(fusetop.or(fusetop2))
+      if METAL_LEVEL != '5LM'
+        via5_ncap = via5.not(fusetop.or(fusetop2))
+        via5_cap  = via5.and(fusetop.or(fusetop2))
+      end
+    end
+  end
+end
+
diff --git a/IC/klayout/lvs/rule_decks/mimcap_connection.lvs b/IC/klayout/lvs/rule_decks/mimcap_connection.lvs
new file mode 100644
index 0000000..c2e6646
--- /dev/null
+++ b/IC/klayout/lvs/rule_decks/mimcap_connection.lvs
@@ -0,0 +1,34 @@
+################################################################################################
+# Copyright 2022 GlobalFoundries PDK Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################################
+
+#==================================
+# ------ MIMCAP CONNECTIONS -------
+#==================================
+
+logger.info('Starting LVS MIMCAP CONNECTIONS')
+
+case MIM_OPTION
+when 'A'
+  connect(metal2, mim_virtual)
+  connect(fuse_cap, via2)
+
+when 'B'
+  connect(topmin1_metal, mimtm_virtual)
+  connect(fuse_cap, top_via)
+  connect(topmin1_metal, mimtm_stack1_virtual)
+  connect(topmin2_metal, mimtm_stack2_virtual)
+  connect(fuse2_cap, topmin1_via)
+end
\ No newline at end of file
diff --git a/IC/klayout/lvs/rule_decks/mimcap_derivations.lvs b/IC/klayout/lvs/rule_decks/mimcap_derivations.lvs
index 2fa2226..de22dc7 100644
--- a/IC/klayout/lvs/rule_decks/mimcap_derivations.lvs
+++ b/IC/klayout/lvs/rule_decks/mimcap_derivations.lvs
@@ -23,7 +23,6 @@
 # mim option A
 # stacked mim cannot exist in 2LM
 mim_virtual = fusetop.sized(1.06.um).and(metal2.interacting(fusetop)).not(fusetop2)
-metal2_ncap = metal2.not(mim_virtual)
 fuse_cap   = fusetop.interacting(lvs_cap)
 fuse2_cap  = fusetop2.interacting(lvs_cap)
 
@@ -32,12 +31,3 @@
 mimtm_stack1_virtual = fusetop.sized(1.06.um).and(topmin1_metal.interacting(fusetop))
 mimtm_stack2_virtual = fusetop2.sized(1.06.um).and(topmin2_metal.interacting(fusetop2))
 
-if METAL_LEVEL != '2LM'
-  metal3_ncap = metal3.not(mimtm_virtual).not(mimtm_stack2_virtual).not(mimtm_stack1_virtual)
-
-  if METAL_LEVEL != '3LM'
-    metal4_ncap = metal4.not(mimtm_virtual).not(mimtm_stack2_virtual).not(mimtm_stack1_virtual)
-    metal5_ncap = metal5.not(mimtm_virtual).not(mimtm_stack2_virtual).not(mimtm_stack1_virtual) if METAL_LEVEL != '4LM'
-  end
-
-end
diff --git a/IC/klayout/lvs/rule_decks/pn_varactor_connection.lvs b/IC/klayout/lvs/rule_decks/pn_varactor_connection.lvs
new file mode 100644
index 0000000..8f4c111
--- /dev/null
+++ b/IC/klayout/lvs/rule_decks/pn_varactor_connection.lvs
@@ -0,0 +1,23 @@
+################################################################################################
+# Copyright 2022 GlobalFoundries PDK Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################################
+
+#========================================
+# ------ PN Varactors CONNECTIONS -------
+#========================================
+
+# pnvar_1p8 varactor nodes connections
+connect(pnvar_1p8_terminal_n, contact)
+connect(pnvar_1p8_terminal_p, contact)
\ No newline at end of file
diff --git a/IC/klayout/lvs/rule_decks/res_connection.lvs b/IC/klayout/lvs/rule_decks/res_connection.lvs
new file mode 100644
index 0000000..813bd1b
--- /dev/null
+++ b/IC/klayout/lvs/rule_decks/res_connection.lvs
@@ -0,0 +1,24 @@
+################################################################################################
+# Copyright 2022 GlobalFoundries PDK Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################################
+
+#================================
+# ---- RESISTOR DERIVATIONS -----
+#================================
+
+logger.info('Starting LVS RESISTOR CONNECTIONS')
+
+connect(nplus_cont, contact)
+connect(pplus_cont, contact)
\ No newline at end of file