System construction#

PolarizableUnit#

class strongcoca.PolarizableUnit(response, position, orientation=None, name='PolarizableUnit', **orientation_kwargs)[source]#

Class for managing polarizable units in CoupledSystem objects along with their position and orientation.

Parameters:
  • response (BaseResponse) – Object that handles response function representations.

  • position (Union[ndarray, Sequence[float]]) – Position of polarizable unit in Å.

  • orientation (Optional[Rotation]) – Orientation of polarizable unit.

  • name (str) – Name of polarizable unit.

  • **orientation_kwargs – Alternative keyword arguments for setting orientation; these arguments are passed to set_orientation().

Examples

The following snippet illustrates how polarizable unit objects can be initialized. Here, an artificial response function is used. In practice the response function would usually be imported from, e.g., TDDFT calculations:

>>> from math import pi
>>> from strongcoca import PolarizableUnit
>>> from strongcoca.response import build_random_casida
>>>
>>> response = build_random_casida(n_states=3, name='Merkat', random_seed=42)
>>> pu = PolarizableUnit(response, [0, 2, -1], name='Apple',
...                      rotation_vector=[0, 0, pi])
>>>
>>> print(pu)
--------------------- PolarizableUnit ----------------------
name              : Apple
response          : Merkat
position (Å)      : [ 0.  2. -1.]
quaternion        : [0. 0. 1. 0.]
rotation_vector   : [0. ... 0. ... 3.14...]
rotation_angle    : 3.14...
property atoms: Atoms#

Atomic structure associated with this polarizable unit (if available).

property broadening: Broadening#

Broadening of the response.

property excitations: Excitations#

Excitations as Excitations. Available only if the underlying response can be represented in this form.

property name: str#

Name of polarizable unit.

property orientation: Rotation#

Orientation of the polarizable unit.

property position: ndarray#

Position of center of mass of polarizable unit.

property response: BaseResponse#

Dielectric response.

set_orientation(rotation=None, quaternion=None, rotation_matrix=None, rotation_vector=None, rotation_axis=None, rotation_angle=None, euler_seq=None, euler_angles=None, units='radians')[source]#

Set the orientation of the polarizable unit.

The orientation can be set in multiple ways that are mutually exclusive.

Parameters:
  • rotation (Optional[Rotation]) – Rotation object.

  • quaternion (Union[ndarray, Sequence[float], None]) – Quaternion as in from_quat().

  • rotation_matrix (Union[ndarray, Sequence[Union[ndarray, Sequence[float]]], None]) – Rotation matrix as in from_matrix().

  • rotation_vector (Union[ndarray, Sequence[float], None]) – Rotation vector as in from_rotvec(); its norm gives the angle of rotation in radians.

  • rotation_axis (Union[ndarray, Sequence[float], None]) – Rotation axis; the given vector is normalized; use together with rotation_angle.

  • rotation_angle (Optional[float]) – Rotation angle (see units); use together with rotation_axis.

  • euler_seq (Optional[str]) – Sequence of axes for Euler rotations as in from_euler(); use together with euler_angles.

  • euler_angles (Union[ndarray, Sequence[float], None]) – Euler angles (see units) as in from_euler(); use together with euler_seq.

  • units (str) – radians or degrees.

Return type:

None

CoupledSystem#

class strongcoca.CoupledSystem(polarizable_units=None, cell=None, pbc=False, name='CoupledSystem')[source]#

Objects of this class represent collections of polarizable units.

Parameters:
  • polarizable_units (Optional[List[PolarizableUnit]]) – Polarizable units comprising the coupled system.

  • cell (Optional[Cell]) – Cell metric (only used for periodic systems).

  • pbc (bool) – True if coupled system is periodic.

  • name (str) – Name of coupled system.

Examples

The following snippet illustrates how a coupled system can be constructed. Here, an artificial response function is used. In practice the response function would usually be imported from, e.g., TDDFT calculations:

>>> from strongcoca import CoupledSystem, PolarizableUnit
>>> from strongcoca.response import build_random_casida
>>>
>>> # set up response function
>>> response = build_random_casida(n_states=3, name='Panda', random_seed=42)
>>>
>>> # set up polarizable units
>>> pu1 = PolarizableUnit(response, [0, 0, 0], name='Eats')
>>> pu2 = PolarizableUnit(response, [2, 0, 0], name='Shoots')
>>> pu3 = PolarizableUnit(response, [0, 2, 0], name='Leafs')
>>>
>>> # construct coupled system
>>> cs = CoupledSystem([pu1, pu2, pu3], name='Panda')
>>> print(cs)
---------------------- CoupledSystem -----------------------
name                 : Panda
pbc                  : False
n_polarizable_units  : 3
  polarizable_unit 0 : Eats
  polarizable_unit 1 : Shoots
  polarizable_unit 2 : Leafs

CoupledSystem objects behave similar to lists with the polarizable units as items as shown by the following examples:

>>> # loop over polarizable units
>>> for pu in cs:
...     print(pu)
--------------------- PolarizableUnit ----------------------
name              : Eats
response          : Panda
position (Å)      : [0. 0. 0.]
...
>>>
>>> # access a particular unit by index
>>> cs[0].name = 'Lime'
>>>
>>> # add another polarizable unit
>>> pu4 = PolarizableUnit(response, [0, 2, 2], name='Bamboo')
>>> cs.append(pu4)
>>>
>>> # add several polarizable units
>>> pu5 = PolarizableUnit(response, [-1, -2, 0], name='Oak')
>>> pu6 = PolarizableUnit(response, [3, -1, 0], name='Elm')
>>> cs.append([pu5, pu6])
append(polarizable_unit)[source]#

Append polarizable unit to this coupled system.

Return type:

None

Example

>>> from strongcoca import CoupledSystem, PolarizableUnit
>>> from strongcoca.response import build_random_casida
>>>
>>> response = build_random_casida(n_states=3, name='Panda', random_seed=42)
>>>
>>> pu1 = PolarizableUnit(response, [0, 0, 0], name='Monkey')
>>> pu2 = PolarizableUnit(response, [2, 0, 0], name='Eats')
>>> pu3 = PolarizableUnit(response, [0, 2, 0], name='Banana')
>>>
>>> cs = CoupledSystem([pu1, pu2])
>>> print(len(cs))
2
>>> cs.append(pu3)
>>> print(len(cs))
3
property cell: Cell | None#

Cell metric of coupled system.

copy()[source]#

Return a shallow copy of the coupled system.

Return type:

CoupledSystem

extend(other)[source]#

Extend the current coupled system by adding the polarizable units from another coupled system.

Return type:

None

Example

>>> from strongcoca import CoupledSystem, PolarizableUnit
>>> from strongcoca.response import build_random_casida
>>>
>>> response = build_random_casida(n_states=3, name='Panda', random_seed=42)
>>>
>>> pu1 = PolarizableUnit(response, [0, 0, 0], name='Donkey')
>>> pu2 = PolarizableUnit(response, [2, 0, 0], name='Camel')
>>> pu3 = PolarizableUnit(response, [0, 2, 0], name='Horse')
>>> pu4 = PolarizableUnit(response, [0, 0, 2], name='Zebra')
>>>
>>> cs1 = CoupledSystem([pu1, pu2])
>>> cs2 = CoupledSystem([pu3, pu4])
>>> print(len(cs1), len(cs2))
2 2
>>> cs1.extend(cs2)
>>> print(len(cs1), len(cs2))
4 2
property name: str#

Name of coupled system.

property pbc: bool#

True if coupled system is periodic.

property positions: List[ndarray]#

Positions of centers of mass of polarizable units.

to_atoms()[source]#

Return the combined atomic configurations of the underlying polarizable units.

Return type:

Atoms