本文整理汇总了Python中grid.Grid.load方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.load方法的具体用法?Python Grid.load怎么用?Python Grid.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grid.Grid
的用法示例。
在下文中一共展示了Grid.load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from grid import Grid [as 别名]
# 或者: from grid.Grid import load [as 别名]
def load( filepath = None, fd = None, close = True):
fd = utils._get_file( "r", filepath, fd)
start_pos = utils._read_2tuple( fd)
finish_pos = utils._read_2tuple( fd)
no_of_allowed_moves = int( utils._readline( fd))
allowed_moves = set()
for i in xrange( no_of_allowed_moves):
allowed_moves.add( utils._read_2tuple( fd))
grid = Grid.load( None, fd, False)
puzzle = MazePuzzle( grid.get_shape())
puzzle._grid = grid
puzzle.set_allowed_moves( allowed_moves)
puzzle.set_start_position( start_pos)
puzzle.set_finish_position( finish_pos)
if close:
fd.close()
return puzzle
示例2: __init__
# 需要导入模块: from grid import Grid [as 别名]
# 或者: from grid.Grid import load [as 别名]
class EFT_calculator:
def __init__(self, order=2):
self.mol = Water()
self.grid = Grid()
self.order = order # order of the interpolant, 1 for linear
# Setup the grid structure. If provided with a data file, load it
def setup(self, filename=None):
if not filename:
self.grid.setup()
else:
self.grid.load(filename)
# Evaluate the Xcom and q for a pair of mols by querying the grid
def eval(self, coors0, coors1):
Xcom0 = self.mol.getCOM(coors0)
Xcom1 = self.mol.getCOM(coors1)
R0 = self.mol.getR(coors0)
q0 = tools.R2q(R0)
R1 = self.mol.getR(coors1)
q1 = tools.R2q(R1)
# move COM of mol0 to origin
X = Xcom1 - Xcom0
# reorient to align mol0 with refCoor
X = np.dot(X, R0)
q = tools.qdiv(q1, q0)
# Use mirror symmetry of mol0 to move mol1 such that its COM has positive y and z values
reflections = []
qsub = q[1:]
for i in self.mol.refl_axes:
if X[i] < 0:
X[i] = -X[i]
# the following operation on q is equivalent to changing R to MRM
# i.e., the probe mol is reflected twice, once in the reference frame,
# once in the molecular frame.
qsub[i] = -qsub[i]
qsub[:] = -qsub
reflections.append(i)
# Use mirror symmetry of mol1 to orient it such that it has positive q[0] and q[1] values
if q[0] < 0:
q = -q
if q[1] < 0:
q[0], q[1], q[2], q[3] = -q[1], q[0], q[3], -q[2]
# convert X, q to polar coordinates
r, phi, theta = tools.xyz2spherical(X)
ophi1, ophi2, otheta = tools.q2spherical(q)
coor = [r, phi, theta, ophi1, ophi2, otheta]
# use the grid to obtain results
eft = self.grid.interpolate(coor, self.order)
ener = eft[0]
force = eft[1:4]
torque = eft[4:7]
# Reverse the operations for mol0 mirror symmetry back
for i in reflections:
force[i] = -force[i]
torque[i] = -torque[i]
torque[:] = -torque
# Reverse the reorientation applied to align mol0 with refCoor
force[:] = np.dot(force, R0.T)
torque[:] = np.dot(torque, R0.T)
return eft