sponge.system.Molecule

查看源文件
class sponge.system.Molecule(atoms: Union[List[Union[str, int]], ndarray] = None, atom_name: Union[List[str], ndarray] = None, atom_type: Union[List[str], ndarray] = None, atom_mass: Union[Tensor, ndarray, List[float]] = None, atom_charge: Union[Tensor, ndarray, List[float]] = None, atomic_number: Union[Tensor, ndarray, List[float]] = None, bonds: Union[Tensor, ndarray, List[int]] = None, coordinate: Union[Tensor, ndarray, List[float]] = None, pbc_box: Union[Tensor, ndarray, List[float]] = None, template: Union[dict, str, List[Union[dict, str]]] = None, residue: Union[Residue, List[Residue]] = None, length_unit: str = None, **kwargs)[源代码]

分子体系层。

参数:
  • atoms (Union[List[Union[str, int]], ndarray]) - 体系中的原子。数据可以是原子名称的字符串,也可以是原子序号的int值。默认值: None

  • atom_name (Union[List[str], ndarray]) - 原子名称字符串的array。默认值: None

  • atom_type (Union[List[str], ndarray]) - 原子种类字符串的array。默认值: None

  • atom_mass (Union[Tensor, ndarray, List[float]]) - 原子质量的array,类型为float,shape为 \((B, A)\) 其中B表示batch size, A表示原子数量。默认值: None

  • atom_charge (Union[Tensor, ndarray, List[float]]) - 原子电荷数的array,类型为float,shape为 \((B, A)\) 。默认值: None

  • atomic_number (Union[Tensor, ndarray, List[float]]) - 原子序数的array,类型为int,shape为 \((B, A)\) 。默认值: None

  • bond (Union[Tensor, ndarray, List[int]]) - 键连接的array,数据类型为int,shape为 \((B, b, 2)\) 其中b表示键数量。默认值: None

  • coordinate (Union[Tensor, ndarray, List[float]]) - 原子位置坐标 \(R\) 的Tensor,shape为 \((B, A, D)\) 其中D表示模拟体系的维度,一般为3,数据类型为float。默认值: None

  • pbc_box (Union[Tensor, ndarray, List[float]]) - 周期性边界条件的box,shape为 \((B, D)\) 或者 \((1, D)\) 。默认值: None

  • template (Union[dict, str, List[Union[dict, str]]]) - 分子的模板。可以是一个MindSPONGE模板格式的字典,也可以是一个MindSPONGE模板文件的字符串。如果输入是一个字符串,该类会优先在MindSPONGE模板的构建路径下( mindsponge.data.template )搜索与输入同名的文件。默认值: None

  • residue (Union[Residue, List[Residue]]) - 残基或残基列表。如果 template 不是 None 的话,只有模板里的残基会被使用。默认值: None

  • length_unit (str) - 长度单位。如果为 None ,则使用全局长度单位。默认值: None

  • kwargs (dict) - 其他参数,用于扩展。

输出:
  • 坐标,shape为 \((B, A, D)\) 的Tensor,其中B表示batch size, A表示原子数量,D表示模拟体系的维度,一般为3。数据类型为float。

  • 周期性边界条件盒子,shape为 \((B, D)\) 的Tensor,其中B表示batch size, D表示模拟体系的维度,一般为3。数据类型为float。

支持平台:

Ascend GPU

样例:

>>> from sponge import Molecule
>>> system = Molecule(atoms=['O', 'H', 'H'],
...                   coordinate=[[0, 0, 0], [0.1, 0, 0], [-0.0333, 0.0943, 0]],
...                   bonds=[[[0, 1], [0, 2]]])
>>> print ('The number of atoms in the system is: ', system.num_atoms)
The number of atoms in the system is:  3
>>> print ('All the atom names in the system are: ', system.atom_name)
All the atom names in the system are:  [['O' 'H' 'H']]
>>> print ('The coordinates of atoms are: \n{}'.format(system.coordinate.asnumpy()))
The coordinates of atoms are:
[[[ 0.      0.      0.    ]
[ 0.1     0.      0.    ]
[-0.0333  0.0943  0.    ]]]
>>> system = Molecule(template='water.spce.yaml')
>>> print ('The number of atoms in the system is: ', system.num_atoms)
The number of atoms in the system is:  3
>>> print ('All the atom names in the system are: ', system.atom_name)
All the atom names in the system are:  [['O' 'H1' 'H2']]
>>> print ('The coordinates of atoms are: \n{}'.format(system.coordinate.asnumpy()))
The coordinates of atoms are:
[[[ 0.          0.          0.        ]
[ 0.08164904  0.0577359   0.        ]
[-0.08164904  0.0577359   0.        ]]]
add_residue(residue: Residue, coordinate: Tensor = None)[源代码]

向当前分子系统增加残基。

参数:
  • residue (class) - 向系统中增加的残基的 Residue 类。

  • coordinate (Tensor) - 输入残基的坐标。默认值: None

append(system)[源代码]

向当前分子系统添加系统。

参数:
  • system (Molecule) - 添加进该分子系统的另一个分子系统。

build_angle()[源代码]

构建系统的角度。

build_atom_charge()[源代码]

构建原子电荷数。

build_atom_type()[源代码]

构建原子种类。

build_dihedrals()[源代码]

构建系统的二面角。

build_h_bonds()[源代码]

构建氢原子键。

build_improper()[源代码]

构建系统不适当的二面角。

build_space(coordinate: Tensor, pbc_box: Tensor = None)[源代码]

构建坐标系和周期性边界条件箱。

参数:
  • coordinate (Tensor) - 系统的初始坐标。如果是 None ,系统会随机生成一个坐标作为它的初始坐标。

  • pbc_box (Tensor) - 系统的初始周期性边界条件箱。如果是 None ,则系统不会使用周期性边界系统。默认值: None

build_system()[源代码]

通过残基构建系统。

calc_colvar(colvar: Colvar) Tensor[源代码]

计算系统中特定的集体变量的值。

参数:
  • colvar (Colvar) - 一般的集体变量 \(s(R)\) 的基类。

返回:

Tensor,集体变量 \(s(R)\) 的值。

calc_image(shift: float = 0) Tensor[源代码]

计算坐标图。

参数:
  • shift (float) - 相对于箱子尺寸 \(\vec{L}\) 的偏移比 \(c\) 。默认值: 0

返回:

Tensor,坐标图。

convert_length_from(unit)[源代码]

从指定的单位转换长度。

参数:
  • unit (Union[str, Units, Length, float, int]) - 长度单位。

返回:

float,从指定单位转换所得长度。

convert_length_to(unit)[源代码]

把长度转换到指定的单位。

参数:
  • unit (Union[str, Units, Length, float, int]) - 长度单位。

返回:

float,根据特定单位换算所得长度。

coordinate_in_pbc(shift: float = 0) Tensor[源代码]

获取在整个周期性边界条件箱中的坐标。

参数:
  • shift (float) - 相对于箱子尺寸的偏移比。默认值: 0

返回:

Tensor,周期性边界条件箱中的坐标。shape为 (B, …, D) ,数据类型为float。

copy(shift: Tensor = None)[源代码]

返回一个复制当前 Molecule 参数的 Molecule 类。

参数:
  • shift (Tensor) - 系统的移动距离。默认值: None

返回:

class,复制了当前 Molecule 类的参数的 Molecule 类。

fill_water(edge: float = None, gap: float = None, box: ndarray = None, pdb_out: str = None, template: str = None)[源代码]

Molecule类中给周期性边界条件箱加水的内部方法。

参数:
  • edge (float) - 系统周围水的边长,默认值 None

  • gap (float) - 系统原子和水原子之间的最小间隔,默认值 None

  • box (Tensor) - 周期性边界条件箱,默认值 None

  • pdb_out (str) - 存放加水后的系统信息的pdb文件的名字,默认值 None

  • template (str) - 加的水分子的补充模板,默认值 None

返回:

Tensor,加水后的周期性边界条件箱。

get_atoms(atoms: Union[Tensor, Parameter, ndarray, str, list, tuple])[源代码]

从系统中获取原子。

参数:
  • atoms (Union[Tensor, Parameter, ndarray, str, list, tuple]) - 原子列表。

返回:

class。原子或一些原子。

get_coordinate(atoms: AtomsBase = None)[源代码]

获取坐标的Tensor。

参数:
  • atoms (class) - 特殊原子群的基类,在MindSPONGE中被用作 atoms group module 。默认值: None

返回:

Tensor,坐标。数据类型为float。

get_pbc_box()[源代码]

获取周期性边界条件箱。

返回:

Tensor。周期性边界条件箱。

get_volume()[源代码]

获得系统的容积。

返回:

Tensor。系统的容积。如果没有使用周期性边界条件箱,容积为None。

property heavy_atom_mask

重原子(非氢原子)的掩码。

返回:

Tensor,重原子的掩码。

property length_unit

长度单位。

返回:

str,长度单位。

move(shift: Tensor = None)[源代码]

移动系统的坐标。

参数:
  • shift (Tensor) - 系统的移动距离。默认值: None

property ndim

原子坐标的维度数量。

返回:

int,原子坐标的维度的数量。

reduplicate(shift: Tensor)[源代码]

复制系统让其扩大到原来的两倍。

参数:
  • shift (Tensor) - 从原始系统移动的距离。

repeat_box(lattices: list)[源代码]

根据周期性边界条件的box的格点重复系统。

参数:
  • lattices (list) - 周期性边界条件箱的格点。

residue_bond(res_id: int)[源代码]

获得残基键的索引。

参数:
  • res_id (int) - 残基ID参数。

返回:

Tensor。残基键的索引。

residue_coordinate(res_id: int)[源代码]

获得残基坐标。

参数:
  • res_id (int) - 残基ID参数。

返回:

Tensor。系统中残基的坐标。

residue_head(res_id: int)[源代码]

获取残基的头索引。

参数:
  • res_id (int) - 残基ID参数。

返回:

Tensor。残基的头索引。

residue_index(res_id: int)[源代码]

获得残基的索引。

参数:
  • res_id (int) - 残基ID参数。

返回:

Tensor。残基在系统中的索引。

residue_tail(res_id: int)[源代码]

获得残基的尾索引。

参数:
  • res_id (int) - 残基ID参数。

返回:

Tensor。残基的尾索引。

set_atom_charge(atom_charge: Tensor)[源代码]

设置原子电荷。

参数:
  • atom_charge (Tensor) - 原子电荷。

set_bond_length(bond_length: Tensor)[源代码]

设置键长。

参数:
  • bond_length (Tensor) - 设置系统的键长。

set_coordianate(coordinate: Tensor)[源代码]

设定坐标的值。

参数:
  • coordinate (Tensor) - 用于设定系统坐标的坐标。

返回:

Tensor,系统的坐标。

set_length_unit(unit)[源代码]

设定系统的长度单位。

参数:
  • unit (Union[str, Units, Length, float, int]) - 长度单位。

set_pbc_box(pbc_box: Tensor = None) Tensor[源代码]

设置周期性边界条件箱。

参数:
  • pbc_box (Tensor) - 设置系统的周期性边界条件箱。如果是None,系统不会使用周期性边界条件箱。默认值: None

返回:

Tensor,系统的周期性边界条件箱。

set_pbc_grad(grad_box: bool)[源代码]

设置是否计算周期性边界条件箱的梯度。

参数:
  • grad_box (bool) - 是否计算周期性边界条件箱的梯度。

返回:

bool,是否计算周期性边界条件箱的梯度。

property shape

原子坐标的shape。

返回:

Tensor,原子坐标的shape。

space_parameters()[源代码]

获取空间的参数(坐标和周期性边界条件箱)。

返回:

list。坐标和周期性边界条件箱。如果周期性边界条件箱未使用,则只返回坐标。

trainable_params(recurse=True)[源代码]

获取可训练参数。

参数:
  • recurse (bool) - 如果为True,则产生此网络层和所有子网络层的参数。否则,只产生作为此网络层直接成员的参数。默认值: True

返回:

list,所有可训练参数的list。

update_coordinate(coordinate: Tensor)[源代码]

更新坐标的参数。

参数:
  • coordinate (Tensor) - 用于更新系统坐标的坐标。

返回:

Tensor。更新后的系统坐标。

update_image(image: Tensor = None)[源代码]

更新坐标图。

参数:
  • image (Tensor) - 用于更新系统坐标图的坐标图。默认值: None

返回:

bool,是否成功更新了系统坐标图。

update_pbc_box(pbc_box: Tensor)[源代码]

更新周期性边界条件箱。

参数:
  • pbc_box (Tensor) - 用于更新系统周期性边界条件箱的周期性边界条件箱。

返回:

Tensor,更新后的周期性边界条件箱。