# include "VectorList.h" void MolscriptDrawLine(NRVectP v1, NRVectP v2) { printf("line %9.4f %9.4f %9.4f\n",v1[1],v1[2],v1[3]); printf(" to %9.4f %9.4f %9.4f ;\n",v2[1],v2[2],v2[3]); } void f_O_gdl_Vector (FILE * ff,double *v, int LineMove) { if (LineMove) { fprintf(ff,"Line %9.4f %9.4f %9.4f\n",v[1],v[2],v[3]); } else { fprintf(ff,"Move %9.4f %9.4f %9.4f\n",v[1],v[2],v[3]); } } /* ============ */ void O_gdl_Vector (double *v, int LineMove) /* ============ */ { if (LineMove) { printf("Line %9.4f %9.4f %9.4f\n",v[1],v[2],v[3]); } else { printf("Move %9.4f %9.4f %9.4f\n",v[1],v[2],v[3]); } } /* ================== */ VectorList * AllocateVectorList (int N, char *name) /* ================== */ { VectorList * V = (VectorList *)calloc(1,sizeof(VectorList)); V->NVects = dmatrix(1,N,1,3); V->Nmax = N; V->Nnow = 0; V->LineMove = ivector(1,N); if (name==NULL) strcpy(V->name,"VECTS"); else strcpy(V->name,name); return V; } /* =============== */ int AddToVectorList /* =============== */ (VectorList * V, double v1, double v2, double v3, int LineMove) { if (V->Nnow == V->Nmax) return 0 ; else { int N = V->Nnow ; N++; V->NVects[N][1] = v1 ; V->NVects[N][2] = v2 ; V->NVects[N][3] = v3 ; V->LineMove[N] = LineMove ; return (V->Nnow = N); } } /* ===================== */ void O_gdl_PrintVectorList (VectorList *V) /* ===================== */ { int N; printf("DRAW_OBJECT_%s t %d 80\n",V->name,V->Nnow+2); printf("Begin_object %s\n",V->name); for (N=1; N<=V->Nnow ; N++) { O_gdl_Vector(V->NVects[N],V->LineMove[N]); } printf("End_object\n"); } /* ================= */ double ** VectorList3dCross (VectorList *V, double * v, double L) /* ================= */ { AddToVectorList(V,v[1]-L,v[2], v[3], 0); AddToVectorList(V,v[1]+L,v[2], v[3], 1); AddToVectorList(V,v[1] ,v[2]-L,v[3], 0); AddToVectorList(V,v[1] ,v[2]+L,v[3], 1); AddToVectorList(V,v[1] ,v[2], v[3]-L,0); AddToVectorList(V,v[1] ,v[2], v[3]+L,1); } /* ===================== */ void VectorListKludgeArrow (VectorList *V, double * v, double *u) /* ===================== */ { double L = LENGTH(second_from_first(u,v)); AddToVectorList(V,v[1],v[2],v[3],0); AddToVectorList(V,u[1],u[2],u[3],1); VectorList3dCross(V,u,L/10); } /* ================= */ void O_gdl_BeginObject(char *s) /* ================= */ { if (s==NULL) { printf("BeginObject A\n"); } else { printf("BeginObject %s\n",s); } } /* =============== */ void O_gdl_EndObject(void) /* =============== */ { printf("EndObject\n"); } /* ============== */ void AIPrint1Vector (double *v, int LineMove) /* ============== */ { if (LineMove) { printf("%9.4f %9.4f L\n",v[1],v[2]); } else { printf("%9.4f %9.4f m\n",v[1],v[2]); } } /* ============= */ double * DrawingLimits(int flag,double *u) /* ============= */ { int i; static double Limits[8] = {0}; double * Max = Limits, * Num = Limits, * Min = Limits + 4 ; if (flag == 1) { *Num = 0 ; Max[1] = Max[2] = Max[3] = -INFINITY ; Min[1] = Min[2] = Min[3] = INFINITY ; } else if (flag == -1) { /* Do Nothing */ ; } else if (flag == 0) { (*Num)++; for (i=1; i<=3 ; i++) { if (u[i] > Max[i]) Max[i] = u[i] ; else if (u[i] < Min[i]) Min[i] = u[i] ; } } return Limits ; } # ifdef OFF /* ============= */ double * MessedupDrawingLimits(int flag,double *u) /* ============= */ { int i; static double Limits[8] = {0}; static Statistic X, Y, Z ; if (flag == 1) { InitStats(&X); InitStats(&Y); InitStats(&Z); } else if (flag == 0){ IncrementStats(&X,u[1]); IncrementStats(&Y,u[2]); IncrementStats(&Z,u[3]); } else if (flag == -1) { /* Do Nothing */ ; } else if (flag == 1) { (*Num)++; for (i=1; i<=3 ; i++) { if (u[i] > Max[i]) Max[i] = u[i] ; else if (u[i] < Min[i]) Min[i] = u[i] ; } } return Limits ; } # endif double * nrMidPoint(PassNRVector3 w,PassNRVector3 u,PassNRVector3 v) { w[1] = 0.5 * (u[1] + v[1]) ; w[2] = 0.5 * (u[2] + v[2]) ; w[3] = 0.5 * (u[3] + v[3]) ; return w; } void PrintBoundingBox(void) { double * Limits = DrawingLimits(-1,NULL); double * Max = Limits, * Num = Limits, * Min = Limits + 4 ; AllocateNRVector3 centroid ; nrMidPoint(centroid,Min,Max); { double x = centroid[1] - US_PAPER_POINTS_WIDTH , y = centroid[2] - US_PAPER_POINTS_LENGTH, xscale = US_PAPER_POINTS_WIDTH * 0.8 / ( Max[1] - Min[1] ) , yscale = US_PAPER_POINTS_LENGTH * 0.8 / ( Max[2] - Min[2] ) , scale = (xscale > yscale ? yscale : xscale ) , dz = Max[3] - Min[3], LineWidthScaleFac = (MAX_LINEWIDTH - MIN_LINEWIDTH) / dz , LineWidthBaseLine = (Max[3]*MIN_LINEWIDTH - Min[3]*MAX_LINEWIDTH) /dz , ScaledLineWidthScaleFac = LineWidthScaleFac / scale , ScaledLineWidthBaseLine = LineWidthBaseLine / scale ; printf("%% %s [%d] PrintBoundingBox(): \n",__FILE__,__LINE__); printf("%% Use the following transformation to get the drawing to fit on US paper\n"); printf("%% Beg_FitToPage\n"); printf("%% %lf %lf translate\n", US_PAPER_POINTS_WIDTH/2.0,US_PAPER_POINTS_LENGTH/2.0); printf("%% %lf %lf scale\n",scale,scale); printf("%% %lf %lf translate\n",-centroid[1],-centroid[2]); printf("%% End_FitToPage\n"); printf("%% LineWidthScaleFactorBaseLine: %lf %lf\n", LineWidthScaleFac,LineWidthBaseLine); printf("%% ScaledLineWidthScaleFactorBaseLine: %lf %lf\n", ScaledLineWidthScaleFac,ScaledLineWidthBaseLine); printf("%% DrawnVectors: %d\n",(int) *Num); printf("%% ZLimits: %lf %lf\n",Min[3],Max[3]); printf("%%%%BoundingBox:%lf %lf %lf %lf\n", Min[1],Min[2],Max[1],Max[2]); } } /* ============ */ void AIPrint1Line (double *u, double *v, double LineWidth) /* ============ */ { DrawingLimits(0,u); DrawingLimits(0,v); printf("%4lf w\n",LineWidth); printf("%9.4f %9.4f m\n",u[1],u[2]); printf("%9.4f %9.4f L\n",v[1],v[2]); printf("S\n"); } void AISimplePrintHeader(void) { printf("%%!PS-Adobe-2.0 EPSF-1.2\n"); printf("%%%%BoundingBox:%d %d %d %d\n",0,0,US_PAPER_POINTS_WIDTH,US_PAPER_POINTS_LENGTH); printf("%%%%TemplateBox:%d %d %d %d\n",0,0,US_PAPER_POINTS_WIDTH,US_PAPER_POINTS_LENGTH); printf("%%%%EndComments\n"); printf("%%%%EndProlog\n"); printf("%% The next line starts out the drawing with:\n"); printf("%% 0 setgray 1 setlinecap 1 setlinejoin\n"); printf("%% These are the setting used by MolScript\n"); printf("0 G 1 J 1 j\n"); } void AISimplePrintTrailer(void) { printf("%%%%Trailer\n"); } /* ============= */ double CalcLineWidth(int flag, double ScaleFactor, double BaseLine, double z) /* ============= */ { static double m,b; if (flag) { m = ScaleFactor ; b = BaseLine; fprintf(stderr,"CalcLineWidth(): Linewidth = %lf * z + %lf\n",m,b) ; return 0 ; } else { return (z * m + b) ; } } void AISimplePrintVectors(VectorList * V) { int N; double Min[4], Max[4]; for (N=1; N<=V->Nnow -1; N++) { double LineWidth = CalcLineWidth(0,0,0,(V->NVects[N][3]+V->NVects[N+1][3])/2); AIPrint1Line(V->NVects[N],V->NVects[N+1],LineWidth); } } void AIDrawCAofSelection(file_records * f) { # define MAX_VECTORS 1000 VectorList * V = AllocateVectorList(MAX_VECTORS,"MolustratorVectors"); int ii, n, DoneFirst = 0; for (ii=0; ii < f->atomnum; ii++) { atom_record * a = f->atoms[ii] ; if (IS_SELECTED_WRT(a,FLAG_1_DESELECT)) { if (!DoneFirst) { AddToVectorList(V,a->x,a->y,a->z,0); DoneFirst = 1; } else { n = AddToVectorList(V,a->x,a->y,a->z,0) ; assert (n != 0) ; } } } AISimplePrintVectors(V); # undef MAX_VECTORS }