本文整理汇总了Python中PyUtils类的典型用法代码示例。如果您正苦于以下问题:Python PyUtils类的具体用法?Python PyUtils怎么用?Python PyUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(self, data = None):
"""Called whenever the curve list is updated. Make sure the curve editor list match the application curve list."""
count = self._appCurveList.getCount()
for i in range(count):
inCurve = self._appCurveList.get(i)
inTrajectory1d = inCurve.getTrajectory1d()
try:
outTrajectory1d = self.getTrajectory(i)
areSameObject = PyUtils.sameObject(inTrajectory1d, outTrajectory1d)
except IndexError:
outTrajectory1d = None
areSameObject = False
if not areSameObject:
# Need to delete or insert
# First, check how many curves we should delete
delete = 1
try:
while not PyUtils.sameObject( inTrajectory1d, self.getTrajectory(i+delete) ) :
delete += 1
except IndexError:
delete = 0
if delete > 0 :
# Delete the specified controllers
self._removeCurveEditors(i,i+delete)
else :
# Insert the specified controller
self._insertCurveEditor(i, inCurve)
# Delete any remaining controllers
self._removeCurveEditors(count)
self.getParent().layout()
示例2: create
def create(self):
"""Creates the instant character based on the available description. Attach a reasonable controller, if available."""
app = wx.GetApp()
try:
wrappedController = PyUtils.wrapCopy( app.getController(0) )
except IndexError:
wrappedController = None
try:
character = app.getCharacter(0)
previousMass = character.getMass()
except IndexError:
previousMass = None
app.deleteAllObjects()
PyUtils.load( "RigidBodies.FlatGround" )
character = self._characterDescription.createCharacter()
character.computeMass()
app.addCharacter(character)
if wrappedController is not None:
controller = wrappedController.createAndFillObject(None, character)
if previousMass is not None:
massRatio = character.getMass() / previousMass
controller.scaleGains( massRatio )
app.addController(controller)
controller.setStance( Core.LEFT_STANCE )
self.connectController()
return character
示例3: load
def load(self):
assert not self._loaded, "Cannot load scenario twice!"
self._loaded = True
# Create the rigid bodies for the main staircase
orientation = PyUtils.angleAxisToQuaternion( (self._angle,(0,1,0)) )
size = MathLib.Vector3d( self._staircaseWidth, self._riserHeight, self._threadDepth )
pos = PyUtils.toPoint3d( self._position ) + MathLib.Vector3d( 0, -self._riserHeight/2.0, 0 )
delta = MathLib.Vector3d(size)
delta.x = 0
delta = orientation.rotate( delta )
for i in range(self._stepCount):
box = PyUtils.RigidBody.createBox( size, pos = pos + delta * (i+1), locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
# Create the rigid bodies for both ramps
rampHeights = ( self._leftRampHeight, self._rightRampHeight )
deltaRamp = MathLib.Vector3d(self._staircaseWidth/2.0,0,0)
deltaRamp = orientation.rotate( deltaRamp )
deltaRamps = (deltaRamp, deltaRamp * -1)
for deltaRamp, rampHeight in zip( deltaRamps, rampHeights ):
if rampHeight is None: continue
deltaRamp.y = rampHeight/2.0
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + delta , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
box = PyUtils.RigidBody.createBox( (0.02,rampHeight,0.02), pos = pos + deltaRamp + (delta * self._stepCount) , locked = True, orientation=orientation )
Physics.world().addRigidBody(box)
deltaRamp.y = rampHeight
rampOrientation = orientation * PyUtils.angleAxisToQuaternion( (math.atan2(self._riserHeight, self._threadDepth), (-1,0,0)) )
rampLen = self._stepCount * math.sqrt( self._riserHeight*self._riserHeight + self._threadDepth*self._threadDepth )
box = PyUtils.RigidBody.createBox( (0.04,0.02,rampLen), pos = pos + deltaRamp + (delta * ((self._stepCount+1) * 0.5)) , locked = True, orientation=rampOrientation )
Physics.world().addRigidBody(box)
示例4: saveController
def saveController(self, event = None):
"""Save the currently selected controller"""
controller = self._getSelectedController()
if controller is None : return
saveNumber = self._saveNumber
if PyUtils.sameObject( self._lastSave[0], controller ) :
if self._lastSave[2] is not None :
saveNumber = self._lastSave[2]
controllerName = controller.getName()
dialogTitle = "Save %s Controller" % controllerName
fileName = "%s_%d.py" % (controllerName, saveNumber)
dialog = wx.FileDialog(self, dialogTitle, self._dirName, fileName, "*.py", wx.SAVE | wx.OVERWRITE_PROMPT )
dialog.CenterOnScreen()
if dialog.ShowModal() == wx.ID_OK:
if saveNumber != self._saveNumber:
self._lastSave = (None, None, None)
else:
self._lastSave = (controller, self._saveNumber, None)
self._saveNumber += 1
fileName=dialog.GetFilename()
self._dirName=dialog.GetDirectory()
pathName = os.path.join(self._dirName,fileName)
file = open(pathName,'w')
file.write( "from App.Proxys import *\n\ndata = %s" % PyUtils.fancify( PyUtils.serialize(controller)) )
file.close()
dialog.Destroy()
示例5: update
def update(self, data = None):
"""Called whenever the tree is updated."""
try:
tree = self._infoTree
rootItem = tree.GetRootItem()
nodeData = tree.GetItemPyData( rootItem )
snapshot = nodeData.getObject().getCurrentSnapshot()
except AttributeError: return
if self._activeTreeItemId != None :
currentSnapshot = tree.GetItemPyData( self._activeTreeItemId )
if PyUtils.sameObject(currentSnapshot, snapshot) : return
tree.SetItemBold( self._activeTreeItemId, False )
# Look for the new item
activeList = [tree.GetFirstChild(rootItem)[0]]
while len(activeList) > 0 :
treeItemId = activeList.pop()
if not treeItemId.IsOk(): continue
object = tree.GetItemPyData( treeItemId ).getObject()
if PyUtils.sameObject(snapshot, object) :
self._activeTreeItemId = treeItemId
tree.SetItemBold( treeItemId, True )
return
activeList.append( tree.GetFirstChild(treeItemId)[0] )
activeList.append( tree.GetNextSibling(treeItemId) )
示例6: update
def update(self, object):
"""Adjusts the node's _subTreeItemIds list so that it matches an input object list.
TreeItemId s will be deleted or inserted into _subTreeItemIds based on its current content and
that of the input object list."""
count = self._member.getCount(object)
for i in range(count):
inObject = self._member.getObject(object,i)
try:
outObject = self.getObject(i)
areSameObject = PyUtils.sameObject(inObject, outObject)
except IndexError:
outObject = None
areSameObject = False
if not areSameObject:
# Need to delete or insert
# First, check how many objects we should delete
delete = 1
try:
while not PyUtils.sameObject( inObject, self.getObject(i+delete) ) :
delete += 1
except IndexError:
delete = 0
if delete > 0 :
# Delete the specified objects
self.removeChildren(i,i+delete)
else :
# Insert the specified object
self.insertChild(i, inObject)
# Delete any remaining objects
self.removeChildren(count)
示例7: createBox
def createBox( size=(1,1,1), position=(0,0,0), colour=(0.6,0.6,0.6) ):
"""
Creates the mesh for a box having the specified size and a specified position.
The size should be a 3-tuple (xSize, ySize, zSize).
The position should be a 3-tuple.
Colour should be a 3-tuple (R,G,B) or a 4-tuple (R,G,B,A)
"""
size = PyUtils.toVector3d(size)
position = PyUtils.toPoint3d(position)
vertices = []
delta = MathLib.Vector3d()
for repeat in range(3):
for x in (-0.5,0.5) :
delta.x = size.x * x
for y in (-0.5,0.5) :
delta.y = size.y * y
for z in (-0.5,0.5) :
delta.z = size.z * z
vertices.append( position + delta )
faces = [(0,1,3,2),(5,4,6,7), # YZ Faces
(9,13,15,11),(12,8,10,14), # XY Faces
(18,19,23,22),(17,16,20,21)] # XZ Faces
return create( vertices, faces, colour )
示例8: _addIndirectVar
def _addIndirectVar(self, varName, initialValue):
"""Add an indirect variable with the given name, as well as its getter and setter."""
if isinstance(initialValue, _Symmetric) :
self.__setattr__( PyUtils.getterName(varName), lambda side: self.getIndirectVarSymmetric(varName, side) )
else:
self.__setattr__( PyUtils.getterName(varName), lambda: self.getIndirectVar(varName) )
self._indirectVarsAreValid = None
self.__setattr__(varName, initialValue)
示例9: DownloadPDBs
def DownloadPDBs(PDB_list_file):
PDB_list = open(os.getcwd()+'/'+PDB_list_file,'r').readlines()
for i in range(len(PDB_list)):
PDBid = PDB_list[i].strip()
PyUtils.create_folder(os.getcwd()+"/"+PDBid)
os.chdir(PDBid)
cmd = ["~/../scripts/pdbUtil/getPdb.pl"+" -id "+PDBid]
subprocess.call(cmd,shell=True)
os.chdir("..")
示例10: _addNativeVar
def _addNativeVar(self, varName, initialValue):
"""Add a variable with he given name, as well as its getter and setter."""
if isinstance(initialValue, _Symmetric) :
self.__setattr__( PyUtils.getterName(varName), lambda side: self.getNativeVarSymmetric(varName, side) )
self.__setattr__( PyUtils.setterName(varName), lambda side, value: self.setNativeVarSymmetric(varName, side, value) )
else :
self.__setattr__( PyUtils.getterName(varName), lambda: self.getNativeVar(varName) )
self.__setattr__( PyUtils.setterName(varName), lambda value: self.setNativeVar(varName, value) )
self.__setattr__( varName, initialValue )
示例11: __init__
def __init__(self, rec, lig, cov, cov_index, HG):
self.rec = rec
self.lig = lig
#self.folder = os.getcwd() + "/"
self.folder = os.path.dirname(os.path.abspath(rec)) + "/"
self.fixed_rec = self.folder + "rec.pdb"
self.fixed_lig = self.folder + "xtal-lig.pdb"
self.cov = cov
self.cov_index = cov_index
self.hg = HG
PyUtils.initPythonVs()
示例12: _createCylinder
def _createCylinder(proxy, axis, basePos, tipPos, radius, colour, moiScale, withMesh):
"""
Private function.
Use createCylinder() or createArticulatedCylinder() instead.
"""
if axis != 0 and axis != 1 and axis != 2:
raise ValueError("Axis must be 0 for x, 1 for y or 2 for z.")
# Mesh and cdps will be set manually
proxy.meshes = None
proxy.cdps = None
# Compute box moi
moi = [0, 0, 0]
height = math.fabs(tipPos - basePos)
for i in range(3):
if i == axis:
moi[i] = proxy.mass * radius * radius / 2.0
else:
moi[i] = proxy.mass * (3 * radius * radius + height * height) / 12.0
### HACK!
moi[i] = max(moi[i], 0.01)
proxy.moi = PyUtils.toVector3d(moi) * moiScale
cylinder = proxy.createAndFillObject()
basePoint = [0, 0, 0]
tipPoint = [0, 0, 0]
basePoint[axis] = basePos
tipPoint[axis] = tipPos
basePoint3d = PyUtils.toPoint3d(basePoint)
tipPoint3d = PyUtils.toPoint3d(tipPoint)
baseToTipVector3d = Vector3d(basePoint3d, tipPoint3d)
if baseToTipVector3d.isZeroVector():
raise ValueError("Invalid points for cylinder: base and tip are equal!")
baseToTipUnitVector3d = baseToTipVector3d.unit()
if height <= radius * 2.0:
cdp = Physics.SphereCDP()
cdp.setCenter(basePoint3d + baseToTipVector3d * 0.5)
cdp.setRadius(height / 2.0)
else:
cdp = Physics.CapsuleCDP()
cdp.setPoint1(basePoint3d + baseToTipUnitVector3d * radius)
cdp.setPoint2(tipPoint3d + baseToTipUnitVector3d * -radius)
cdp.setRadius(radius)
cylinder.addCollisionDetectionPrimitive(cdp)
if withMesh:
mesh = Mesh.createCylinder(basePoint, tipPoint, radius, colour)
cylinder.addMesh(mesh)
return cylinder
示例13: __init__
def __init__(self, rec, lig, cov, cov_index, HG, tart=False):
self.tart = bool(tart)
self.rec = rec
self.lig = lig
self.folder = os.path.dirname(os.path.abspath(rec)) + "/"
self.fixed_rec = self.folder + "rec.pdb"
self.fixed_lig = self.folder + "xtal-lig.pdb"
self.cov = cov
self.cov_index = cov_index
self.hg = HG
PyUtils.initPythonVs()
示例14: __init__
def __init__(self, folder_name, compound, library = False):
self.folder = os.getcwd() + "/"
self.name = self.folder + folder_name + "/"
#self.compound = os.path.abspath(compound)[5:]
self.compound = compound
self.library = library
PyUtils.create_folder(self.name)
self.copyIndock()
self.softlink()
os.chdir(self.name)
self.dock_command = Paths.DOCKBASE + "docking/DOCK/src/i386/dock64"
self.DOCK()
示例15: poses2pdb
def poses2pdb(self):
PyUtils.create_folder('recs')
os.chdir('poses')
for k in range(1, len(os.listdir(os.getcwd())) + 1):
i = str(k) + '.mol2'
surface = PYMOLUtils.get_surface_area(i)
with open(i, 'r') as f_mol:
for line in f_mol:
if 'SMILES' in line:
smile_line = line.split()[2]
if 'heavy atom count' in line:
heavy_atoms = int(line.split()[-1])
break
if surface < 200 or surface / heavy_atoms < 14.5:
self.counters.append(0)
continue
if '[N+](=O)[O-]' in smile_line or smile_line.count('N') + smile_line.count('O') + smile_line.count('n') + smile_line.count('o') > 4:
self.counters.append(0)
continue
pdb_pose = '../recs/' + i[:-4] + 'pdb'
subprocess.call(['convert.py', i, pdb_pose])
hetatm = []
with open(pdb_pose, 'r') as f_pdb:
for line in f_pdb:
if 'HETATM' in line:
hetatm.append(line[:23] + ' -1' + line[26:])
rec_pose = '../recs/rec_' + i[:-4] + 'pdb'
with open(rec_pose, 'w') as f_rec:
for line in hetatm:
f_rec.write(line)
for line in self.rec_lines:
f_rec.write(line)
sub_command = []
for res_l in self.res_list:
sub_command.append('-seed_residue')
sub_command.append(str(res_l))
subprocess.call(['python', Paths.SCRIPTS + 'HBonanza.py', '-trajectory_filename', rec_pose, '-hydrogen_bond_distance_cutoff', '3.0', '-hydrogen_bond_angle_cutoff', '30', '-seed_residue', '-1'] + sub_command + ['-just_immediate_connections', 'true'], stdout=open(os.devnull, 'w'))
os.remove(rec_pose + '.average_hbonds')
os.remove(rec_pose + '.frame_by_frame_hbonds.csv')
if os.path.isfile(rec_pose + '.hbond_averages_in_occupancy_column.pdb'):
os.remove(rec_pose + '.hbond_averages_in_occupancy_column.pdb')
counter = self.countHbonds(rec_pose + '.HBonds')
else:
counter = 0
self.counters.append(counter)
os.remove(rec_pose)
os.chdir('../')
shutil.rmtree('recs')
shutil.rmtree('poses')