PyFrag
Public Member Functions | Public Attributes | Properties | List of all members
qmworks.plams.core.basemol.Atom Class Reference
Inheritance diagram for qmworks.plams.core.basemol.Atom:
Inheritance graph
[legend]
Collaboration diagram for qmworks.plams.core.basemol.Atom:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, atnum=0, symbol=None, coords=None, unit='angstrom', bonds=None, mol=None, other)
 
def str (self, symbol=True, suffix='', unit='angstrom', space=14, decimal=6)
 
def __str__ (self)
 
def __iter__ (self)
 
def translate (self, vector, unit='angstrom')
 
def move_to (self, point, unit='angstrom')
 
def distance_to (self, point, unit='angstrom', result_unit='angstrom')
 
def vector_to (self, point, unit='angstrom', result_unit='angstrom')
 
def angle (self, point1, point2, point1unit='angstrom', point2unit='angstrom', result_unit='radian')
 
def rotate (self, matrix)
 

Public Attributes

 atnum
 
 mol
 
 bonds
 
 properties
 
 coords
 

Properties

 x = property(_getx, _setx)
 
 y = property(_gety, _sety)
 
 z = property(_getz, _setz)
 
 symbol = property(_getsymbol, _setsymbol)
 
 mass = property(_getmass)
 
 radius = property(_getradius)
 
 connectors = property(_getconnectors)
 

Detailed Description

A class representing a single atom in three dimensional space.

An instance of this class has the following attributes:
    *   ``atnum`` -- atomic number (zero for "dummy atoms")
    *   ``coords`` -- tuple of length 3 storing spatial coordinates
    *   ``bonds`` -- list of bonds (see |Bond|) this atom is a part of
    *   ``mol`` -- a |Molecule| this atom belongs to
    *   ``properties`` -- a |Settings| instance storing all other information about this atom (initially it is populated with *\*\*other* keyword arguments passed to the constructor)

All the above attributes can be accessed either directly or using one of the following properties:
    *   ``x``, ``y``, ``z`` -- allow to read or modify each coordinate separately
    *   ``symbol`` -- allows to read or write atomic symbol directly. Atomic symbol is not stored as an attribute, instead of that atomic number (``atnum``) indicates the type of atom. In fact, ``symbol`` this is just a wrapper around ``atnum`` that uses |PeriodicTable| as a translator::

            >>> a = Atom(atnum=8)
            >>> print a.symbol
            O
            >>> a.symbol = 'Ca'
            >>> print a.atnum
            20

    *   ``mass`` -- atomic mass, obtained from |PeriodicTable|, read only
    *   ``radius`` -- atomic radius, obtained from |PeriodicTable|, read only
    *   ``connectors`` -- number of connectors, obtained from |PeriodicTable|, read only

.. note::

    When creating a new atom, its type can be chosen either by setting an atomic number or a symbol (``atnum`` and ``symbol`` constructor arguments). Symbol takes precedence -- if it is supplied, ``atnum`` argument is ignored.


Values stored in ``coords`` tuple do not necessarily have to be numeric, you can also store any string there. This might come handy for programs that allow parametrization of coordinates in the input file (to enforce some geometry constraints for example)::

        >>> a = Atom(symbol='C', coords=(1,2,3))
        >>> print a
                 C       1.00000       2.00000       3.00000
        >>> a.y = 'param1'
        >>> print a
                 C       1.00000        param1       3.00000

However, non-numerical coordinates cannot be used together with some methods (for example :meth:`distance_to` or :meth:`translate`). Trying to do this will raise an exception.

Internally, atomic coordinates are always expressed in angstroms. Most of methods that read or modify atomic coordinates accept keyword argument ``unit`` allowing to choose unit in which results and/or arguments are expressed (see |Units| for details). Throughout the entire code angstrom is the default length unit. If you don't specify ``unit`` parameter in any place of your script, all automatic unit handling described above boils down to occasional multiplication/division by 1.0.

Member Function Documentation

◆ __iter__()

def qmworks.plams.core.basemol.Atom.__iter__ (   self)
Iteration through atom yields coordinates. Thanks to that instances of |Atom| can be passed to any method requiring point or vector as an argument.

◆ __str__()

def qmworks.plams.core.basemol.Atom.__str__ (   self)
Return a string representation of this atom. Simplified version of :meth:`str` to work as a magic method.
Here is the call graph for this function:

◆ angle()

def qmworks.plams.core.basemol.Atom.angle (   self,
  point1,
  point2,
  point1unit = 'angstrom',
  point2unit = 'angstrom',
  result_unit = 'radian' 
)
Calculate an angle between vectors pointing from this atom to *point1* and *point2*.

*point1* and *point2* should be iterable containers of length 3 (for example: tuple, |Atom|, list, numpy array). Values stored in them are expressed in, respectively, *point1unit* and *point2unit*. Returned value is expressed in *result_unit*.

This method requires all coordinates to be numerical values, :exc:`~exceptions.TypeError` is raised otherwise.
Here is the call graph for this function:

◆ distance_to()

def qmworks.plams.core.basemol.Atom.distance_to (   self,
  point,
  unit = 'angstrom',
  result_unit = 'angstrom' 
)
Measure the distance between this atom and *point*.

*point* should be an iterable container of length 3 (for example: tuple, |Atom|, list, numpy array). *unit* describes unit of values stored in *point*. Returned value is expressed in *result_unit*.

This method requires all coordinates to be numerical values, :exc:`~exceptions.TypeError` is raised otherwise.
Here is the caller graph for this function:

◆ move_to()

def qmworks.plams.core.basemol.Atom.move_to (   self,
  point,
  unit = 'angstrom' 
)
Move this atom to a given *point* in space, expressed in *unit*.

*point* should be an iterable container of length 3 (for example: tuple, |Atom|, list, numpy array). *unit* describes unit of values stored in *point*.

This method requires all coordinates to be numerical values, :exc:`~exceptions.TypeError` is raised otherwise.

◆ rotate()

def qmworks.plams.core.basemol.Atom.rotate (   self,
  matrix 
)
Rotate this atom according to rotation *matrix*.

*matrix* should be a container with 9 numerical values. It can be a list (tuple, numpy array etc.) listing matrix elements row-wise, either flat (``[1,2,3,4,5,6,7,8,9]``) or in two-level fashion (``[[1,2,3],[4,5,6],[7,8,9]]``).

.. note::

    This method does not check if supplied matrix is a proper rotation matrix.

◆ str()

def qmworks.plams.core.basemol.Atom.str (   self,
  symbol = True,
  suffix = '',
  unit = 'angstrom',
  space = 14,
  decimal = 6 
)
Return a string representation of this atom.

Returned string is a single line (no newline characters) that always contains atomic coordinates (and maybe more). Each atomic coordinate is printed using *space* characters, with *decimal* characters reserved for decimal digits. Coordinates values are expressed in *unit*.

If *symbol* is ``True``, atomic symbol is added at the beginning of the line. If *symbol* is a string, this exact string is printed there.

*suffix* is an arbitrary string that is appended at the end of returned line. It can contain identifiers in curly brackets (like for example ``f={fragment}``) that will be replaced by values of corresponding attributes (in this case ``self.fragment``). It is done via new string formatting and entire ``self.__dict__`` is passed to formating method. See :ref:`new-string-formatting` for details.

Example:

    >>> a = Atom(atnum=6, coords=(1,1.5,2))
    >>> print a.str()
     C      1.000000      1.500000      2.000000
    >>> print a.str(unit='bohr')
     C      1.889726      2.834589      3.779452
    >>> print a.str(symbol=False)
  1.000000      1.500000      2.000000
    >>> print a.str(symbol='C2.13')
 C2.13      1.000000      1.500000      2.000000
    >>> print a.str(suffix='protein1')
     C      1.000000      1.500000      2.000000 protein1
    >>> a.info = 'membrane'
    >>> print a.str(suffix='subsystem={info}')
     C      1.000000      1.500000      2.000000 subsystem=membrane
Here is the caller graph for this function:

◆ translate()

def qmworks.plams.core.basemol.Atom.translate (   self,
  vector,
  unit = 'angstrom' 
)
Move this atom in space by *vector*, expressed in *unit*.

*vector* should be an iterable container of length 3 (usually tuple, list or numpy array). *unit* describes unit of values stored in *vector*.

This method requires all coordinates to be numerical values, :exc:`~exceptions.TypeError` is raised otherwise.

◆ vector_to()

def qmworks.plams.core.basemol.Atom.vector_to (   self,
  point,
  unit = 'angstrom',
  result_unit = 'angstrom' 
)
Calculate a vector from this atom to *point*.

*point* should be an iterable container of length 3 (for example: tuple, |Atom|, list, numpy array). *unit* describes unit of values stored in *point*. Returned value is expressed in *result_unit*.

This method requires all coordinates to be numerical values, :exc:`~exceptions.TypeError` is raised otherwise.
Here is the caller graph for this function:

The documentation for this class was generated from the following file: