parameters: (self)
return_statement: return topology
docstring: Create an OpenMM Topology object from the stored bonded network
docstring_summary: Create an OpenMM Topology object from the stored bonded network
docstring_tokens: Create an OpenMM Topology object from the stored bonded network
function: def topology(self):
          """ Create an OpenMM Topology object from the stored bonded network """
          try:
              return self._topology
          except AttributeError:
              # If none exists, we need to create it
              pass
          # Cache the topology for easy returning later
          self._topology = topology = Topology()
  
          last_chain = None
          last_residue = None
          # Add each chain (separate 'system's) and residue
          for atom in self.atom_list:
              resid = '%d%s' % (atom.residue.idx, atom.residue.inscode)
              if atom.system != last_chain:
                  chain = topology.addChain(atom.system)
                  last_chain = atom.system
                  last_residue = None
              if resid != last_residue:
                  last_residue = resid
                  residue = topology.addResidue(atom.residue.resname, chain, str(atom.residue.idx), atom.residue.inscode)
              if atom.type is not None:
                  # This is the most reliable way of determining the element
                  atomic_num = atom.type.atomic_number
                  if atomic_num != 0:
                      elem = element.Element.getByAtomicNumber(atomic_num)
              else:
                  # Figure it out from the mass
                  elem = element.Element.getByMass(atom.mass)
              topology.addAtom(atom.name, elem, residue)
  
          # Add all of the bonds
          atoms = list(topology.atoms())
          # Assign atom indexes to make sure they're current
          self.atom_list.assign_indexes()
          for bond in self.bond_list:
              topology.addBond(atoms[bond.atom1.idx], atoms[bond.atom2.idx])
  
          # Add the periodic box if there is one
          if self.box_vectors is not None:
              topology.setPeriodicBoxVectors(self.box_vectors)
  
          return topology
function_tokens: def topology ( self ) : try : return self . _topology except AttributeError : # If none exists, we need to create it pass # Cache the topology for easy returning later self . _topology = topology = Topology ( ) last_chain = None last_residue = None # Add each chain (separate 'system's) and residue for atom in self . atom_list : resid = '%d%s' % ( atom . residue . idx , atom . residue . inscode ) if atom . system != last_chain : chain = topology . addChain ( atom . system ) last_chain = atom . system last_residue = None if resid != last_residue : last_residue = resid residue = topology . addResidue ( atom . residue . resname , chain , str ( atom . residue . idx ) , atom . residue . inscode ) if atom . type is not None : # This is the most reliable way of determining the element atomic_num = atom . type . atomic_number if atomic_num != 0 : elem = element . Element . getByAtomicNumber ( atomic_num ) else : # Figure it out from the mass elem = element . Element . getByMass ( atom . mass ) topology . addAtom ( atom . name , elem , residue ) # Add all of the bonds atoms = list ( topology . atoms ( ) ) # Assign atom indexes to make sure they're current self . atom_list . assign_indexes ( ) for bond in self . bond_list : topology . addBond ( atoms [ bond . atom1 . idx ] , atoms [ bond . atom2 . idx ] ) # Add the periodic box if there is one if self . box_vectors is not None : topology . setPeriodicBoxVectors ( self . box_vectors ) return topology