chemcoord.zmat_functions.DummyManipulation

class chemcoord.zmat_functions.DummyManipulation(dummy_manipulation_allowed, cls=None)[source]

Contextmanager that controls the behaviour of safe_loc() and safe_iloc().

In the following examples it is assumed, that using the assignment with safe_loc() would lead to an invalid reference. Then there are two possible usecases:

with DummyManipulation(zmat, True):
    zmat.safe_loc[...] = ...
    # This inserts required dummy atoms and removes them,
    # if they are not needed anymore.
    # Removes only dummy atoms, that were automatically inserted.

with DummyManipulation(zmat, False):
    zmat.safe_loc[...] = ...
    # This raises an exception
    # :class:`~chemcoord.exceptions.InvalidReference`.
    # which can be handled appropiately.
    # The zmat instance is unmodified, if an exception was raised.