Пример #1
0
    def __init__(self, pairs, numbers, orders=None):
        """Initialize a molecular graph

        Arguments:
          pairs -- See base class (Graph) documentation
          numbers -- consecutive atom numbers
          orders -- bond orders

        When the nature of an atom or a bond is unclear ambiguous, set the
        corresponding integer to zero. This means the nature of the atom or bond
        is unspecified. When the bond orders are not given, they are all set to
        zero.

        If you want to use 'special' atom types, use negative numbers. The same
        for bond orders. e.g. a nice choice for the bond order of a hybrid bond
        is -1.
        """
        if orders is None:
            orders = numpy.zeros(len(pairs), dtype=int)
        elif len(orders) != len(pairs):
            raise ValueError("The number of (bond) orders must be equal to the number of pairs")
        Graph.__init__(self, pairs, len(numbers))
        self._numbers = numpy.array(numbers)
        self._numbers.setflags(write=False)
        self._orders = numpy.array(orders)
        self._orders.setflags(write=False)
Пример #2
0
    def __init__(self, edges, numbers, orders=None, symbols=None, num_vertices=None):
        """
           Arguments:
            | ``edges``  --  See base class (Graph) documentation
            | ``numbers``  --  consecutive atom numbers

           Optional arguments:
            | ``orders``  --  bond orders
            | ``symbols``  --  atomic symbols
            | ``num_vertices``  --  must be the same as the number of atoms or None

           When the nature of an atom or a bond is unclear ambiguous, set the
           corresponding integer to zero. This means the nature of the atom or
           bond is unspecified. When the bond orders are not given, they are all
           set to  zero.

           If you want to use 'special' atom types, use negative numbers. The
           same for bond orders. e.g. a nice choice for the bond order of a
           hybrid bond is -1.
        """
        if num_vertices is not None and num_vertices != len(numbers):
            raise ValueError('The number of vertices must be the same as the number of atoms.')
        if orders is None:
            orders = numpy.ones(len(edges), float)
        Graph.__init__(self, edges, len(numbers))
        self.numbers = numbers
        self.orders = orders
        self.symbols = symbols
Пример #3
0
    def __init__(self,
                 edges,
                 numbers,
                 orders=None,
                 symbols=None,
                 num_vertices=None):
        """
           Arguments:
            | ``edges``  --  See base class (Graph) documentation
            | ``numbers``  --  consecutive atom numbers

           Optional arguments:
            | ``orders``  --  bond orders
            | ``symbols``  --  atomic symbols
            | ``num_vertices``  --  must be the same as the number of atoms or None

           When the nature of an atom or a bond is unclear ambiguous, set the
           corresponding integer to zero. This means the nature of the atom or
           bond is unspecified. When the bond orders are not given, they are all
           set to  zero.

           If you want to use 'special' atom types, use negative numbers. The
           same for bond orders. e.g. a nice choice for the bond order of a
           hybrid bond is -1.
        """
        if num_vertices is not None and num_vertices != len(numbers):
            raise ValueError(
                'The number of vertices must be the same as the number of atoms.'
            )
        if orders is None:
            orders = np.ones(len(edges), float)
        Graph.__init__(self, edges, len(numbers))
        self.numbers = numbers
        self.orders = orders
        self.symbols = symbols