Ejemplo n.º 1
0
 def _test_if_can_be_added(self, other):
     cols = ['atom', 'b', 'a', 'd']
     if not (np.alltrue(self.loc[:, cols] == other.loc[:, cols])
             and np.alltrue(self.index == other.index)):
         message = ("You can add only those zmatrices that have the same "
                    "index, use the same construction table, have the same "
                    "ordering... The only allowed difference is in the "
                    "columns ['bond', 'angle', 'dihedral']")
         raise PhysicalMeaning(message)
Ejemplo n.º 2
0
    def set_index(self,
                  keys,
                  drop=True,
                  append=False,
                  inplace=False,
                  verify_integrity=False):
        """Set the DataFrame index (row labels) using one or more existing
        columns.

        Wrapper around the :meth:`pandas.DataFrame.set_index` method.
        """

        if drop is True:
            try:
                assert type(keys) is not str
                dropped_cols = set(keys)
            except (TypeError, AssertionError):
                dropped_cols = set([keys])

        if not self._required_cols <= (set(self.columns) - set(dropped_cols)):
            raise PhysicalMeaning('You drop a column that is needed to '
                                  'be a physical meaningful description '
                                  'of a molecule.')

        if inplace:
            self._frame.set_index(keys,
                                  drop=drop,
                                  append=append,
                                  inplace=inplace,
                                  verify_integrity=verify_integrity)
        else:
            new = self._frame.set_index(keys,
                                        drop=drop,
                                        append=append,
                                        inplace=inplace,
                                        verify_integrity=verify_integrity)
            return self.__class__(new,
                                  _metadata=self._metadata,
                                  metadata=self.metadata)
Ejemplo n.º 3
0
    def __init__(self, frame, metadata=None, _metadata=None):
        """How to initialize a Zmat instance.

        Args:
            init (pd.DataFrame): A Dataframe with at least the columns
                ``['atom', 'b', 'bond', 'a', 'angle',
                'd', 'dihedral']``.
                Where ``'atom'`` is a string for the elementsymbol.
            order_of_definition (list like): Specify in which order
                the Zmatrix is defined. If ``None`` it just uses
                ``self.index``.

        Returns:
            Zmat: A new zmat instance.
        """
        if not self._required_cols <= set(frame.columns):
            raise PhysicalMeaning('There are columns missing for a '
                                  'meaningful description of a molecule')
        self._frame = frame.copy()
        if metadata is None:
            self.metadata = {}
        else:
            self.metadata = metadata.copy()

        if _metadata is None:
            self._metadata = {}
        else:
            self._metadata = copy.deepcopy(_metadata)

        def fill_missing_keys_with_defaults(_metadata):
            if 'last_valid_cartesian' not in _metadata:
                _metadata['last_valid_cartesian'] = self.get_cartesian()
            if 'has_dummies' not in _metadata:
                _metadata['has_dummies'] = {}

        fill_missing_keys_with_defaults(self._metadata)
Ejemplo n.º 4
0
 def columns(self, value):
     if not self._required_cols <= set(value):
         raise PhysicalMeaning('There are columns missing for a '
                               'meaningful description of a molecule')
     self._frame.columns = value