def computeMSMSvolume(atmCoords, atmRadii, pRadius, dens ):
    srf = MSMS(coords=atmCoords, radii=atmRadii)
    srf.compute(probe_radius=pRadius, density=dens)
    vf, vi, f = srf.getTriangles()
    
    vertices=vf[:,:3]
    normals=vf[:,3:6]
    triangles=f[:,:3]
    return meshVolume(vertices, normals, triangles)
Ejemplo n.º 2
0
def computeMSMSvolume(atmCoords, atmRadii, pRadius, dens):
    srf = MSMS(coords=atmCoords, radii=atmRadii)
    srf.compute(probe_radius=pRadius, density=dens)
    vf, vi, f = srf.getTriangles()

    vertices = vf[:, :3]
    normals = vf[:, 3:6]
    triangles = f[:, :3]
    return meshVolume(vertices, normals, triangles)
def findIsoValueMol(radii, coords, blobbyness, data, isoDensity, targetValue, target):
    """Find the best isocontour value (isovalue) for a molecule
at one specific blobbyness by reproducing the targetValue
for a target (area or volume)
INPUT:
	mol:		molecule recognizable by MolKit
	blobbyness:	blobbyness
	data: 		blurred data
	isoDensity: 	density of surface vertices for finding isovalue only
	targetValue: 	value of the target, to be reproduced
	target: 	Area or Volume
OUTPUT:
	target:		(as input)
	targetValue:	(as input)
	value:		reproduced value of target
	isovalue:	the best isocontour value
	v1d:		vertices of generated blur surface
	t1d:		faces of generated blur surface
	n1d:		normals of the vertices
"""
    

    # Initialization
    isovalue = 1.0  		# guess starting value
    mini = 0.
    maxi = 99.
    cutoff = targetValue*0.01	# 99% reproduction of targetValue
    accuracy = 0.0001		# accuracy of isovalue
    stepsize = 0.5		# step size of increase/decrease of isovalue
    value_adjust = 1.0		# adjustment of value
    value = 0.0
    
    # Optimize isovalue
    while True:
        print "------- isovalue = %f -------" % isovalue

        # 1. Isocontour
	print "... ... 1. Isocontour ......"
        v1, t1, n1 = computeIsocontour(isovalue, data)
        if len(v1)==0 or len(t1)==0:
            value    = 0.0
            maxi     = isovalue
            isovalue = maxi - (maxi-mini)*stepsize
	    print "***** isocontoured surface has no vertices *****", len(v1), ", ", len(t1)
            continue
	
	# 2. Remove small components (before decimate)
	print "... ... 2. Remove small components ......"
        v1, t1, n1 = findComponents(v1, t1, n1, 1)
	
	# 3. Decimate
	print "... ... 3. Decimate ......"
        v1d, t1d, n1d = decimate(v1, t1, n1, isoDensity)
        if len(v1d)==0 or len(t1d)==0:
            value    = 0.0
            maxi     = isovalue
            isovalue = maxi - (maxi-mini)*stepsize
            continue
	#################### Analytical normals for decimated vertices #####################
        normals = computeBlurCurvature(radii, coords, blobbyness, v1d)   # Analytical Blur curvatures
	n1d = normals.tolist()
	####################################################################################
	
        # 4. Compute value
	print "... ... 4. Compute value ......"
	if target == "Area":
	    value = meshArea(v1d, t1d)
	else:
            n1d = normalCorrection(n1d, t1d) 	# replace zero normals
	    print "calling meshVolume after normalCorrection"
	    value  = meshVolume(v1d, n1d, t1d)

	# 5. Adjust value
	print "... ... 5. Adjust value ......"
	value *= value_adjust
	
	# TEST
        print "target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f"%(
            	target, targetValue, value, isovalue, maxi, mini)
		
	# 6. Evaluate isocontour value
	print "... ... 6. Evaluate isovalue ......"
        if fabs(value - targetValue) < cutoff:	# Satisfy condition!
            print "Found: target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f"%(
           	   target, targetValue, value, isovalue, maxi, mini)
            break

        if maxi-mini < accuracy:		# can not find good isovalue
            print "Not found: target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f"%(
            	   target, targetValue, value, isovalue, maxi, mini)
            return target, targetValue, value, 0.0, v1, t1, n1

        if value > targetValue: 		# value too big, increase isovalue
            mini = isovalue
            isovalue = mini + (maxi-mini)*stepsize
        else: 					# value too small, decrease isovalue
            maxi = isovalue
            isovalue = maxi - (maxi-mini)*stepsize

    # Return
    return target, targetValue, value, isovalue, v1, t1, n1
Ejemplo n.º 4
0
def findIsoValueMol(radii, coords, blobbyness, data, isoDensity, targetValue,
                    target):
    """Find the best isocontour value (isovalue) for a molecule
at one specific blobbyness by reproducing the targetValue
for a target (area or volume)
INPUT:
	mol:		molecule recognizable by MolKit
	blobbyness:	blobbyness
	data: 		blurred data
	isoDensity: 	density of surface vertices for finding isovalue only
	targetValue: 	value of the target, to be reproduced
	target: 	Area or Volume
OUTPUT:
	target:		(as input)
	targetValue:	(as input)
	value:		reproduced value of target
	isovalue:	the best isocontour value
	v1d:		vertices of generated blur surface
	t1d:		faces of generated blur surface
	n1d:		normals of the vertices
"""

    # Initialization
    isovalue = 1.0  # guess starting value
    mini = 0.
    maxi = 99.
    cutoff = targetValue * 0.01  # 99% reproduction of targetValue
    accuracy = 0.0001  # accuracy of isovalue
    stepsize = 0.5  # step size of increase/decrease of isovalue
    value_adjust = 1.0  # adjustment of value
    value = 0.0

    # Optimize isovalue
    while True:
        print "------- isovalue = %f -------" % isovalue

        # 1. Isocontour
        print "... ... 1. Isocontour ......"
        v1, t1, n1 = computeIsocontour(isovalue, data)
        if len(v1) == 0 or len(t1) == 0:
            value = 0.0
            maxi = isovalue
            isovalue = maxi - (maxi - mini) * stepsize
            print "***** isocontoured surface has no vertices *****", len(
                v1), ", ", len(t1)
            continue

# 2. Remove small components (before decimate)
        print "... ... 2. Remove small components ......"
        v1, t1, n1 = findComponents(v1, t1, n1, 1)

        # 3. Decimate
        print "... ... 3. Decimate ......"
        v1d, t1d, n1d = decimate(v1, t1, n1, isoDensity)
        if len(v1d) == 0 or len(t1d) == 0:
            value = 0.0
            maxi = isovalue
            isovalue = maxi - (maxi - mini) * stepsize
            continue
#################### Analytical normals for decimated vertices #####################
        normals = computeBlurCurvature(radii, coords, blobbyness,
                                       v1d)  # Analytical Blur curvatures
        n1d = normals.tolist()
        ####################################################################################

        # 4. Compute value
        print "... ... 4. Compute value ......"
        if target == "Area":
            value = meshArea(v1d, t1d)
        else:
            n1d = normalCorrection(n1d, t1d)  # replace zero normals
            print "calling meshVolume after normalCorrection"
            value = meshVolume(v1d, n1d, t1d)

# 5. Adjust value
        print "... ... 5. Adjust value ......"
        value *= value_adjust

        # TEST
        print "target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f" % (
            target, targetValue, value, isovalue, maxi, mini)

        # 6. Evaluate isocontour value
        print "... ... 6. Evaluate isovalue ......"
        if fabs(value - targetValue) < cutoff:  # Satisfy condition!
            print "Found: target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f" % (
                target, targetValue, value, isovalue, maxi, mini)
            break

        if maxi - mini < accuracy:  # can not find good isovalue
            print "Not found: target=%6s, targetValue=%10.3f, value=%10.3f, isovalue=%7.3f, maxi=%7.3f, mini=%7.3f" % (
                target, targetValue, value, isovalue, maxi, mini)
            return target, targetValue, value, 0.0, v1, t1, n1

        if value > targetValue:  # value too big, increase isovalue
            mini = isovalue
            isovalue = mini + (maxi - mini) * stepsize
        else:  # value too small, decrease isovalue
            maxi = isovalue
            isovalue = maxi - (maxi - mini) * stepsize

    # Return
    return target, targetValue, value, isovalue, v1, t1, n1