コード例 #1
0
def tstTravelSurfInsideMesh(tstFileName, phiFileName, threshold="auto"):
  '''calculates the burial depth'''
  print "reading in tst and phi files"
  tstD = tstdata.tstData(
      tstFileName,
      necessaryKeys=tstdata.tstData.necessaryKeysForMesh + ['PDB_RECORD'])
  phiData = phi(phiFileName)  # read in the phimap if possible
  if 'CONVEX_HULL_TRI_POINT_LIST' not in tstD.dict.keys():
    print "Run tstConvexHull.py on this tst data file first."
    sys.exit(1)
  #these sets are useful to construct
  convexHullPoints = set()
  for record in tstD.dict['CONVEX_HULL_TRI_POINT_LIST']:
    convexHullPoints.update(record[1:])
  maxPhi = phiData.getMaxValues()
  if threshold == "auto" and maxPhi == 1.0:
    threshold = 0.6
  if threshold == "auto" and maxPhi == 10.0:
    threshold = 6.0
  gridD, mins, maxs = grid.makeTrimmedGridFromPhi(
      phiData, tstD.dict['POINT_XYZ'], convexHullPoints, threshold, 0, -2, 2)
  gridSize = 1.0 / phiData.scale
  del phiData  # no longer needed in this function, so delete this reference
  #do the biggest disjoint set of tris/points stuff
  allPoints, allTris, cavPoints, cavTris = cavity.assumeNoCavities(
      tstD.dict['POINT_XYZ'], tstD.dict['TRIANGLE_POINT'],
      tstD.dict['POINT_NEIGHBOR'])
  #here is where code is mesh-specific
  print "setting up mesh data structure"
  meshData = mesh.mesh(
      gridD, tstD.dict['POINT_XYZ'], tstD.dict['POINT_NEIGHBOR'],
      gridSize, -2, 0, "X")  # no between
  print "calculating burial depth"
  meshData.calculateTravelDistance("travelin", [3], [1])
  gridTravelInDepth = meshData.getGridTravelDistance(gridD, "travelin")
  #tstdebug.debugGridCountVals(gridTravelInDepth)
  print "writing phi file output"
  phiDataOut = phi()
  phiDataOut.createFromGrid(
      gridTravelInDepth, gridSize, toplabel="travel depth surf-in")
  phiDataOut.write(tstFileName+".mesh.travel.in.phi")
  print "writing pdb file output"
  pdbD = pdb.pdbData()
  for line in tstD.dict['PDB_RECORD']:
    pdbD.processLine(line)
  atomTravelInDepths = grid.assignAtomDepths(
      gridTravelInDepth, gridSize, mins, maxs, pdbD)
  #make a pdb file with the bfactor replaced
  for index, atomTID in enumerate(atomTravelInDepths):
    pdbD.updateFactors(index, (pdbD.factors[index][0], atomTID))
  pdbD.write(tstFileName+".mesh.travelin.pdb")
  #also add record to tstD
  atomTIDRecord = []
  for index, atomTID in enumerate(atomTravelInDepths):
    atomTIDRecord.append([index + 1, atomTID])
  print "updating tst file"
  tstD.dict['ATOM_TRAVEL_IN'] = atomTIDRecord
  #write data into tst file
  tstFile = open(tstFileName, 'a')
  tstFile.write("ATOM_TRAVEL_IN\n")
  for line in tstD.dict['ATOM_TRAVEL_IN']:
    lineOut = "%8d" % line[0]
    for count in xrange(1, len(line)):
      lineOut += "%+9.4f " % line[count]
    noPlusLine = string.replace(lineOut, "+", " ")
    tstFile.write(noPlusLine)
    tstFile.write("\n")
  tstFile.write("END ATOM_TRAVEL_IN\n")
  tstFile.close()
  print "burial depth done"
コード例 #2
0
def tstTravelSurfInside(tstFileName, phiFileName=False):
  tstD = tstdata.tstData(tstFileName)  # read the file into the data structure
  phiData = phi(phiFileName)   # read in the phimap if possible
  if 'CONVEX_HULL_TRI_POINT_LIST' not in tstD.dict.keys():
    print "Run tstConvexHull.py on this tst data file first."
    sys.exit(1)
  #these sets are useful to construct
  convexHullPoints = set()
  for record in tstD.dict['CONVEX_HULL_TRI_POINT_LIST']:
    convexHullPoints.update(record[1:])
  gridD, mins, maxs = grid.makeTrimmedGridFromPhi(
      phiData, tstD.dict['POINT_XYZ'], convexHullPoints, 0.6, 0, -2.0, 2)
  gridSize = 1.0/phiData.scale
  del phiData  # no longer needed in this function, so delete this reference
  #do the biggest disjoint set of tris/points stuff
  allPoints, allTris, cavPoints, cavTris = cavity.assumeNoCavities(
      tstD.dict['POINT_XYZ'], tstD.dict['TRIANGLE_POINT'],
      tstD.dict['POINT_NEIGHBOR'])
  #here's the (relatively simple) surface travel distance calculation finally
  #  assign following encoding -1 = outside ch, 0 = on border,
  #   pos ints = dist from border, -2 = far inside ms,
  #   other neg ints = -(dist)-3
  #whole algorithm wrapped into big function...
  extraEdges, surfaceEdgeBoxes = grid.findLongSurfEdges(
      tstD.dict['POINT_XYZ'], tstD.dict['POINT_NEIGHBOR'], gridSize, mins, maxs)
  for surfaceEdgeBox in surfaceEdgeBoxes.keys():
    x, y, z = gridD[surfaceEdgeBox[0]][surfaceEdgeBox[1]][surfaceEdgeBox[2]][1:]
    gridD[surfaceEdgeBox[0]][surfaceEdgeBox[1]][surfaceEdgeBox[2]] = (
        -1., x, y, z)
  pointTravelDist, traceback, volumePointDepths = \
      travelDistNoMesh.calcTravelDist(
          gridD, tstD.dict['POINT_XYZ'], gridSize, mins, maxs, allPoints,
          extraEdges, surfaceEdgeBoxes, tstFileName)
  #transform grid to actual travel distance
  maxTD = grid.finalizeGridTravelDist(gridD, gridSize)
  phiDataOut = phi()
  phiDataOut.createFromGrid(gridD, gridSize, toplabel="travel depth surf-in")
  phiDataOut.write(tstFileName+".travel.in.phi")
  pdbD = pdb.pdbData()
  for line in tstD.dict['PDB_RECORD']:
    pdbD.processLine(line)
  atomTravelInDepths = grid.assignAtomDepths(gridD, gridSize, mins, maxs, pdbD)
  #make a pdb file with the bfactor replaced
  for index, atomTID in enumerate(atomTravelInDepths):
    pdbD.updateFactors(index, (pdbD.factors[index][0], atomTID))
  pdbD.write(tstFileName+".travelin.pdb")
  #also add record to tstdata
  atomTIDRecord = []
  for index, atomTID in enumerate(atomTravelInDepths):
    atomTIDRecord.append([index+1, atomTID])
  tstD.dict['ATOM_TRAVEL_IN'] = atomTIDRecord
  #write data into tst file
  tstFile = open(tstFileName, 'a')
  tstFile.write("ATOM_TRAVEL_IN\n")
  for line in tstD.dict['ATOM_TRAVEL_IN']:
    lineOut = "%8d" % line[0]
    for count in xrange(1, len(line)):
      lineOut += "%+9.4f " % line[count]
    noPlusLine = string.replace(lineOut, "+", " ")
    tstFile.write(noPlusLine)
    tstFile.write("\n")
  tstFile.write("END ATOM_TRAVEL_IN\n")
  tstFile.close()