CCL Home Page
Up Directory CCL stergrap.c
/**************************************************************************/
/**************************************************************************/
/**************************   "steric"   **********************************/
/**************************************************************************/
/*************     Program to calculate ligand cone    ********************/
/*************     angles as a measure of steric size  ********************/
/**************************************************************************/
/**************************************************************************/

/**************************************************************************/
/******************      Graphics Functions      **************************/
/**************************************************************************/
/******************        This module is        **************************/
/******************      system independant      **************************/
/**************************************************************************/

#include 
#include 
#include 
#include 

#include "sterdefn.h"      /* declaration of structures and globals       */
#include "stergrap.h"      /* functions for all graphical visualisations  */
#include "sterfile.h"      /* functions for all file manipulations        */
#include "stermem.h"       /* dynamic memory management module            */
#include "steraid.h"       /* additional functions needed                 */
#include "stertext.h"      /* all text functions for text mode            */
#include "stercomm.h"      /* command menu options                        */
#include "stercalc.h"      /* commands associated with calculations       */

/**************************************************************************/
/**************************************************************************/

int Draw_Steric_Profile(char *args, Mol *M, Set *set, char mode)
{
  FILE *MF=NULL;
  Ster *ster=NULL;
  char line[LINELEN];
  double rad=0.0;
  double gap=0.0;
  int i,len,j;
  char fname[100];
  char pname[100];
  char tname[100];
  char lname[100];

  if(M==NULL) return(0);
  if((len=strlen(args))<1) return(0);
  strcpy(fname,M->Fname);
  if((len==1)&&(args[0]==ANGU))
  {
    New_Extension(fname,".ang");
    sprintf(line,"Plotting molecule angular profile to file %s",fname);
  }
  else
  {
    New_Extension(fname,".rad");
    if(len==1) sprintf(line,"Plotting molecule radial profile to file %s",fname);
    else sprintf(line,"Plotting molecule radial profiles to file %s",fname);
  }
  Out_Message(line,O_NEWLN);
  if((MF=fopen(fname,"wt"))==NULL)
  {
    Error_Message(E_OPNOUT,"Draw Steric Profile");
  }
  else
  {
    for(i=0;iname);
      ster=Which_Ster(args[i],M->ster,set);
      if(ster!=NULL)
      {
        fprintf(MF,"#STERIC  %c %10.6f%10.6f%10.6f%10.6f%10.6f  %s\n",ster->type
                  ,ster->tot_val,ster->err_val
                  ,ster->tot_con,ster->err_con
                  ,ster->max_val,ster->name);
        if(ster->val!=NULL)
        {
          fprintf(MF,"#PROFIL  %10.6f%10.6f%6d  %s\n"
                    ,ster->min,ster->max,ster->size,ster->name);
          rad=ster->min;
          gap=(ster->max-ster->min)/ster->size;
          for(j=0;jsize;j++,rad+=gap)
          {
            fprintf(MF,"%10.6f %10.6f\n",rad,ster->val[j]);
          }
          fprintf(MF,"\n");
        }
      }
    }
    fclose(MF);
    strcpy(pname,fname);
    New_Extension(pname,".plt");
    strcpy(tname,fname);
    New_Extension(tname,".TeX");
    strcpy(lname,fname);
    New_Extension(lname,"");
    if((MF=fopen(pname,"wt"))==NULL)
    {
      Error_Message(E_OPNOUT,"Draw Steric Profile");
      return(0);
    }
    else
    {
      if(mode==POLA) fprintf(MF,"set polar\n");
      fprintf(MF,"set title \"\\LARGE %s profile of %s\" , 4\n",ster->name,lname);
      fprintf(MF,"set terminal latex courier 12\n");
      fprintf(MF,"set output \"%s\"\n",tname);
      fprintf(MF,"plot \"%s\" with lines\n",fname);
      fprintf(MF,"exit\n");
      fclose(MF);
      sprintf(line,"sterplot %s",lname); system(line);
      if((set->plot==NULL)&&((set->plot=(FILE *)popen("gnuplot","w"))==NULL))
      {
        Error_Message(E_BADFRK,"Draw Steric Profile");
        return(0);
      }
    }
  }
  return(1);
}

/**************************************************************************/

int Draw_Steric_Parameter(char *args, Mol *molecule, Set *set)
{
  FILE *MF=NULL;
  Mol *M=NULL;
  Ster *ster=NULL;
  char line[LINELEN];
  int i,n,j,m=0;
  char fname[100];
  char pname[100];
  char tname[100];
  char lname[100];

  if(molecule==NULL) return(0);
  strcpy(fname,"sterpar.val");
  sprintf(line,"Plotting steric values to file %s",fname);
  Out_Message(line,O_NEWLN);
  if((MF=fopen(fname,"wt"))==NULL)
  {
    Error_Message(E_OPNOUT,"Draw Steric Parameter");
  }
  else
  {
    fprintf(MF,"#STERIC Parameter Table for Statistics\n");
    for(i=0,M=First_Molecule(molecule);M!=NULL;M=M->next,i++)
    {
      for(j=0,ster=First_Steric(M->ster);ster!=NULL;ster=ster->next,j++)
      {
        if(ster->type==args[0]) m=j;
        fprintf(MF," %14s %c %10.6f%10.6f%10.6f%10.6f"
                  ,M->name,ster->type
                  ,ster->tot_val,ster->tot_con
                  ,ster->max_val,ster->pr_area);
      }
      fprintf(MF,"\n");
    }
    fclose(MF);
    strcpy(pname,fname);
    New_Extension(pname,".plt");
    strcpy(tname,fname);
    New_Extension(tname,".TeX");
    strcpy(lname,fname);
    New_Extension(lname,"");
    if((j>0)&&((MF=fopen(pname,"wt"))==NULL))
    {
      Error_Message(E_OPNOUT,"Draw Steric Parameter");
      return(0);
    }
    else
    {
      fprintf(MF,"set title \"\\LARGE Steric Parameters\" , 4\n");
      fprintf(MF,"set terminal latex courier 12\n");
      fprintf(MF,"set output \"%s\"\n",tname);
      if((set->plot==NULL)&&((set->plot=(FILE *)popen("gnuplot","w"))==NULL))
      {
        Error_Message(E_BADFRK,"Draw Steric Profile");
        return(0);
      }
      fprintf(set->plot,"set title \"Steric Parameters\" , 4\n");
      if(j==1)
      {
        ster=molecule->ster;
        fprintf(set->plot,"set ylabel \"%s\"\n",ster->name);
        fprintf(set->plot,"set xlabel \"Molecules\"\n");
        fprintf(set->plot,"plot \"%s\" using 3",fname);
        fprintf(MF,"set ylabel \"%s\"\n",ster->name);
        fprintf(MF,"set xlabel \"Molecules\"\n");
        fprintf(MF,"plot \"%s\" using 3",fname);
      }
      else
      {
        ster=Goto_Steric(molecule->ster,m+1);
        fprintf(set->plot,"set xlabel \"%s\"\n",ster->name);
        fprintf(set->plot,"set ylabel \"Steric Parameter\"\n");
        fprintf(MF,"set xlabel \"%s\"\n",ster->name);
        fprintf(MF,"set ylabel \"Steric Parameter\"\n");
      }
      for(n=0;nplot,"plot "); fprintf(MF,"plot "); }
        if(n==m) continue;
        ster=Goto_Steric(molecule->ster,n+1);
        fprintf(set->plot,"\"%s\" using %d:%d title \"Total %s\"",fname,3+6*m,3+6*n,ster->name);
        fprintf(MF,"\"%s\" using %d:%d title \"Total %s\"",fname,3+6*m,3+6*n,ster->name);
        if(nplot,", ");fprintf(MF,", ");}
      }
      fprintf(set->plot,"\n");
      fflush(set->plot);
      fprintf(MF,"\nexit\n");
      fclose(MF);
      sprintf(line,"sterplot %s",lname); system(line);
    }
  }
  return(1);
}

/**************************************************************************/

int Draw_Molecule_Contour(Mol *M, Set *set, char *script)
{
  char line[LINELEN];
  char fname[LINELEN];
  char mode='c';
  if(set->mode&PERS_BIT) mode='p';
  else mode='c';
  strcpy(fname,M->Fname);
  if(fname[0]==0) sprintf(fname,"M%d",Get_Molecule_Number(M));
  sprintf(line,"Loading gnuplot to plot %s to postscript",fname);
  Out_Message(line,O_NEWLN);
  sprintf(line,"%s %s %c r %f s %d &"
              ,script,fname,mode,set->rotation,set->c_size);
  return(system(line));
}

/**************************************************************************/

int Draw_Special_View(Mol *M, Set *set)
{
  FILE *MF=NULL;
  char line[LINELEN];
  char fname[100];
  char pname[100];
  char tname[100];
  char lname[100];
  struct vector Mv[100];
  double radius[100];
  struct vector v;
  struct matrix Rotation;
  int count, found, x, y;
  double xm, ym;
  Atms *atom=NULL;

  if(M==NULL) return(0);
  strcpy(fname,M->Fname);
  New_Extension(fname,".view");
  sprintf(line,"Plotting molecule special view to file %s",fname);
  Out_Message(line,O_NEWLN);
  if((MF=fopen(fname,"wt"))==NULL)
  {
    Error_Message(E_OPNOUT,"Draw Special View");
  }
  else
  {
    fprintf(MF,"#STERIC %s\n",M->name);
    v=VequalV(M->basis_z);
    Rotation.x=VequalV(M->basis_x);
    Rotation.y=VequalV(M->basis_y);
    Rotation.z=VequalV(M->basis_z);
    v=Mtransform(Rotation,v);
    for(found=0,atom=First_Atom(M->atoms);atom!=NULL;atom=atom->next)
    {
      if(atom->stat&MAIN_BIT)
      {
        Mv[found]=Mtransform(Rotation,atom->v);
        radius[found]=atom->radius;
        if(found>=100) break;
        found++;
      }
    }

    for(x=-set->x_ran;x<=set->x_ran;x++)
    {
      xm=(double)x/(double)set->x_ran;
      for(y=-set->y_ran;y<=set->y_ran;y++)
      {
        ym=(double)y/(double)set->y_ran;
        for(count=0;countplot==NULL)&&((set->plot=(FILE *)popen("gnuplot","w"))==NULL))
      {
        Error_Message(E_BADFRK,"Draw Special View");
        return(0);
      }
      fprintf(set->plot,"set nopolar\n");
      fprintf(set->plot,"plot \"%s\"\n",fname);
      fflush(set->plot);
    }
  }
  return(1);
}

/**************************************************************************/

int Draw_Projected_View(Mol *M, Set *set)
{
  FILE *MF=NULL;
  char line[LINELEN];
  char fname[100];
  char pname[100];
  char tname[100];
  char lname[100];
  char mode=0;

  double angle=0.0, gap=0.0;
  int a=0;
  double x, y;
  Atms *atom=NULL;

  if(M==NULL) return(0);
  strcpy(fname,M->Fname);
  New_Extension(fname,".proj");
  sprintf(line,"Plotting molecule projected view to file %s",fname);
  Out_Message(line,O_NEWLN);
  if((MF=fopen(fname,"wt"))==NULL)
  {
    Error_Message(E_OPNOUT,"Draw Projected View");
  }
  else
  {
    gap=2*PI/(double)PROJ_RAN;
    fprintf(MF,"#STERIC %s\n",M->name);
    for(atom=First_Atom(M->atoms);atom!=NULL;atom=atom->next)
    {
      if(atom->stat&MAIN_BIT)
      {
        if(atom->stat&CALC_BIT) mode=1;
        for(a=0;a<=PROJ_RAN;a++)
        {
          angle=(double)a*gap;
          x=atom->tv.x+atom->radius*cos(angle);
          y=atom->tv.y+atom->radius*sin(angle);
          fprintf(MF,"%10.5f %10.5f\n",x,y);
          if((set->modev&FADE_BIT)&&(mode==0)) fprintf(MF,"\n");
        }
        fprintf(MF,"\n");
      }
    }
    fclose(MF);

    sprintf(line,"Loading gnuplot to plot file %s",fname);
    Out_Message(line,O_NEWLN);
    strcpy(pname,fname);
    New_Extension(pname,".plt");
    strcpy(tname,fname);
    New_Extension(tname,".TeX");
    strcpy(lname,fname);
    New_Extension(lname,"");
    if((MF=fopen(pname,"wt"))==NULL)
    {
      Error_Message(E_OPNOUT,"Draw Projected View");
      return(0);
    }
    else
    {
      fprintf(MF,"set title \"\\LARGE Projected view of %s\" , 4\n",lname);
      fprintf(MF,"set terminal latex courier 12\n");
      fprintf(MF,"set output \"%s\"\n",tname);
      fprintf(MF,"plot \"%s\"\n",fname);
      fprintf(MF,"exit\n");
      fclose(MF);
      sprintf(line,"sterplot %s",lname); system(line);
      if((set->plot==NULL)&&((set->plot=(FILE *)popen("gnuplot","w"))==NULL))
      {
        Error_Message(E_BADFRK,"Draw Projected View");
        return(0);
      }
      fprintf(set->plot,"set nopolar\n");
      fprintf(set->plot,"plot \"%s\" with lines\n",fname);
      fflush(set->plot);
    }
  }
  return(1);
}

/**************************************************************************/
/**************************************************************************/
/*************************  The End ... ***********************************/
/**************************************************************************/
Modified: Fri Dec 8 17:00:00 1995 GMT
Page accessed 5487 times since Sat Apr 17 21:59:55 1999 GMT