本文整理汇总了Python中Matrix.invert_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.invert_matrix方法的具体用法?Python Matrix.invert_matrix怎么用?Python Matrix.invert_matrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.invert_matrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_symmetries
# 需要导入模块: import Matrix [as 别名]
# 或者: from Matrix import invert_matrix [as 别名]
def group_symmetries(group, center, axis, mol):
from Commands import CommandError
g0 = group[:1].lower()
if g0 in ('c', 'd'):
# Cyclic or dihedral symmetry: C<n>, D<n>
try:
n = int(group[1:])
except ValueError:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
if n < 2:
raise CommandError, 'Cn or Dn with n = %d < 2' % (n,)
if g0 == 'c':
tflist = cyclic_symmetries(n)
else:
tflist = dihedral_symmetries(n)
elif g0 == 'i':
# Icosahedral symmetry: i[,<orientation>]
import Icosahedron as icos
gfields = group.split(',')
if len(gfields) == 1:
orientation = '222'
elif len(gfields) == 2:
orientation = gfields[1]
if not orientation in icos.coordinate_system_names:
raise CommandError, ('Unknown icosahedron orientation "%s"'
% orientation)
else:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
tflist = icos.icosahedral_symmetry_matrices(orientation)
elif g0 == 'h':
# Helical symmetry: h,<repeat>,<rise>[,<angle>[,<n>,<offet>]]
gfields = group.split(',')
nf = len(gfields)
if nf < 3 or nf > 6:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
try:
param = [float(f) for f in gfields[1:]]
except ValueError:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
if len(param) == 2:
param.append(360.0)
if len(param) == 3:
param.append(int(param[0]))
if len(param) == 4:
param.append(0)
repeat, rise, angle, n, offset = param
tflist = helical_symmetry(repeat, rise, angle, n, offset)
elif g0 == 't':
# Translation symmetry: t,<n>,<distance> or t,<n>,<dx>,<dy>,<dz>
gfields = group.split(',')
nf = len(gfields)
if nf != 3 and nf != 5:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
try:
param = [float(f) for f in gfields[1:]]
except ValueError:
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
n = param[0]
if n != int(n):
raise CommandError, 'Invalid symmetry group syntax "%s"' % group
if nf == 3:
delta = (0,0,param[1])
else:
delta = param[1:]
tflist = translation_symmetry(n, delta)
elif group.lower() == 'biomt':
# BIOMT biological unit matrices from PDB file header.
if not hasattr(mol, 'pdbHeaders'):
msg = 'Molecule %s has no BIOMT matrices or PDB headers' % mol.name
raise CommandError, msg
from PDBmatrices import pdb_biomt_matrices
tflist = pdb_biomt_matrices(mol.pdbHeaders)
if len(tflist) == 0:
msg = 'Molecule %s has no BIOMT matrices in PDB header' % mol.name
raise CommandError, msg
from Matrix import is_identity_matrix
if len(tflist) == 1 and is_identity_matrix(tflist[0]):
msg = 'Molecule %s has only identity BIOMT matrix in PDB header' % mol.name
raise CommandError, msg
else:
raise CommandError, 'Unknown symmetry group "%s"' % group
# Apply center and axis transformation.
if tuple(center) != (0,0,0) or tuple(axis) != (0,0,1):
import Matrix as m
tf = m.multiply_matrices(m.vector_rotation_transform(axis, (0,0,1)),
m.translation_matrix([-c for c in center]))
tfinv = m.invert_matrix(tf)
tflist = [m.multiply_matrices(tfinv, t, tf) for t in tflist]
return tflist