#----------------------------------------------------------------------- # Primitive tsxPython sample script # Alpha-helix (protein motif) 1 # Lathe # # $Id$ #----------------------------------------------------------------------- import ptsxpy as p from math import * org = Vec3f( 0., 0., 0. ) xaxis = Vec3f( 1., 0., 0. ) yaxis = Vec3f( 0., 1., 0. ) zaxis = Vec3f( 0., 0., 1. ) r1 = 1. # radius pitch1 = ( 5.4 / 2.3 ) * r1 # pitch (wave length) of the helix t = 0.05 * r1 # thickness of the ribbon w = 0.5 * r1 # width of the ribbon nround = 3.5 # cycles to be drawn (revolutions per height) jperp = 2 # number of joints per pitch #-------------------- # Make a helical ribbon #-------------------- # Make a rectangle as a cross section of the ribbon pl1 = p.CreatePlane( 1, 1 ) p.SceneAddObject( pl1, e_tsxFALSE ) vec1 = Vec3f( t, w, 1. ) p.GNodeScale( pl1, vec1.p, e_tsxWorldFrame ) # Extrude the rectangle helically p.LatheSetSegments( 200 ) p.LatheSetHelix( -pitch1 ) # minus value for right-handed helix p.LatheSetRadius( r1 ) p.LatheSetRotation( 0 ) if tscode == 66: mag1 = 10. else: mag1 = 1. p.LatheSetAngle( int( nround * 360 * mag1 ) ) p.PointsLathe() ## End the edit mode p.PointsClear() #p.PointsDeactivateEdit() #p.SelectNext() #p.SelectPrev() he1 = p.GetCurrentSelection() print( "he1=", he1 ) p.GNodeSetLocation( he1, org.p ) p.GNodeRotate( he1, org.p, xaxis.p, -pi / 2., e_tsxWorldFrame ) # Adjust axes position in case of tS7 Model side and tS6.6 if tscode == 66: vec1 = Vec3f( -1., 0., 0. ) p.GNodeTranslate( he1, vec1.p, e_tsxWorldFrame ) p.MNodeSetAxesPosition( he1, org.p ) # Reset axes orientation # In case of tS7 Model and tS6.6, the helix's z-axis points world +y now. # In case of other tS, x-axis points world +y now. ax1 = Axes3f((1.,0.,0.),(0.,1.,0.),(0.,0.,1.)) p.MNodeSetAxesOrientation( he1, ax1.p ) #-------------------- # Make a skeleton (bones connected in series) #-------------------- jlst1 = [] # Create a skeleton with 2 bones skel1wk = Ulong() jo1wk = Ulong() bo1wk = Ulong() bo2wk = Ulong() p.SkeletonCreate( skel1wk.p, jo1wk.p, e_tsxJOINT_HINGE, org.p, bo1wk.p, bo2wk.p ) skel1 = skel1wk.get() p.SceneAddObject( skel1, 0 ) vec1 = Vec3f() p.JointGetLocation( jo1wk.get(), vec1.p ) print( "j ", vec1.prt() ) vec1 = Vec3f( 5., 5., 1. / jperp ) p.GNodeScale( skel1, vec1.p, e_tsxWorldFrame ) jlst1.append( jo1wk.get() ) p.JointGetLocation( jo1wk.get(), vec1.p ) print( "j ", vec1.prt() ) # Add new joints (and bones) below the last movable bone, one after # another. jo2 = Ulong() bo3 = Ulong() if tscode == 43: lastbone = bo1wk.get() else: lastbone = bo2wk.get() a = int( nround * jperp ) + 1 for i in range( a ): #loc2 = Vec3f( 0., 0., -i * 0.5 * pitch1 ) loc2 = Vec3f( 0., 0., -( i + 1 ) * pitch1 / jperp ) p.SkeletonAddBranch( skel1, jo2.p, e_tsxJOINT_CUSTOM, loc2.p, lastbone, bo3.p ) jlst1.append( jo2.get() ) lastbone = bo3.get() b = 3. * pi / 180. for i in range( len( jlst1 ) ): jo = jlst1[ i ] p.JointSetDoF( jo, tsxJOINT_DOF_PITCH | tsxJOINT_DOF_YAW | tsxJOINT_DOF_ROLL | tsxJOINT_DOF_TRANS_X | tsxJOINT_DOF_TRANS_Y | tsxJOINT_DOF_TRANS_Z ) # Set DOF (degrees of freedom) for sliding p.JointSetMinLimit( jo, tsxJOINT_DOF_TRANS_X, 0. ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_TRANS_X, 0. ) p.JointSetMinLimit( jo, tsxJOINT_DOF_TRANS_Y, 0. ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_TRANS_Y, 0. ) p.JointSetMinLimit( jo, tsxJOINT_DOF_TRANS_Z, -0.1 ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_TRANS_Z, 0.1 ) # Set DOF for bending p.JointSetMinLimit( jo, tsxJOINT_DOF_PITCH, -b ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_PITCH, b ) p.JointSetMinLimit( jo, tsxJOINT_DOF_YAW, -b ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_YAW, b ) p.JointSetMinLimit( jo, tsxJOINT_DOF_ROLL, 0. ) p.JointSetMaxLimit( jo, tsxJOINT_DOF_ROLL, 0. ) #p.GNodeDraw( skel1 ) #-------------------- # Adjust position and size and attach the helix to the skeleton #-------------------- vec1 = Vec3f() p.GNodeGetSize( he1, vec1.p ) print( "vec1=", vec1.prt() ) #if tscode == 66: vec2 = Vec3f( 0., 0., vec1.z() / 2. ) p.GNodeTranslate( he1, vec2.p, e_tsxWorldFrame ) p.GNodeTranslate( skel1, vec2.p, e_tsxWorldFrame ) p.SkeletonAttachSkin( skel1, he1 ) p.SceneDraw()