Exemplo n.º 1
0
float ShakerDoLine(float *v0, float *v1, float *v2,
                   float *p0, float *p1, float *p2, float wt)
{
  /* v0-v1-v2 */

  float d0[3], d1[3], cp[3], d2[3], d3[3], d4[3], push[3];
  float dev, sc, lcp, result;

  subtract3f(v2, v1, d2);
  subtract3f(v0, v1, d1);
  normalize3f(d2);
  normalize23f(d1, d0);

  cross_product3f(d2, d0, cp);
  lcp = (float) length3f(cp);
  if(lcp > R_SMALL4) {
    lcp = 1.0F / lcp;
    scale3f(cp, lcp, cp);       /* axis 0 */

    subtract3f(v2, v0, d3);
    normalize3f(d3);            /* axis 1 */

    cross_product3f(cp, d3, d4);
    normalize3f(d4);            /* displacement direction */

    dev = dot_product3f(d1, d4);        /* current deviation */

    if((result = (float) fabs(dev)) > R_SMALL8) {
      sc = wt * dev;
      scale3f(d4, sc, push);
      add3f(push, p1, p1);
      scale3f(push, 0.5F, push);
      subtract3f(p0, push, p0);
      subtract3f(p2, push, p2);
    } else {
      result = 0.0;
    }
  } else
    result = 0.0;
  return result;

}
Exemplo n.º 2
0
float ShakerDoPyra(float targ1, float targ2,
                   float *v0, float *v1, float *v2, float *v3,
                   float *p0, float *p1, float *p2, float *p3, float wt, float inv_wt)
{
  float d0[3], cp[3], d2[3], d3[3];
  float av[3], t0[3], push[3];

  float cur, dev, sc, result1, result2 = 0.0F;

  add3f(v1, v2, av);
  subtract3f(v2, v1, d2);
  add3f(v3, av, av);
  subtract3f(v3, v1, d3);
  subtract3f(av, v0, t0);
  cross_product3f(d2, d3, cp);
  scale3f(av, 0.33333333F, av);
  normalize3f(cp);
  subtract3f(av, v0, d0);

  cur = dot_product3f(d0, cp);
  dev = cur - targ1;
  result1 = (float) fabs(dev);
  if(result1 > R_SMALL8) {
    sc = wt * dev;
    if((cur * targ1) < 0.0)     /* inverted */
      sc = sc * inv_wt;         /* inversion fixing weight */
    scale3f(cp, sc, push);
    add3f(push, p0, p0);
    scale3f(push, 0.333333F, push);
    subtract3f(p1, push, p1);
    subtract3f(p2, push, p2);
    subtract3f(p3, push, p3);
  }

  if((targ2 >= 0.0F) && ((cur * targ1 > 0.0) || (fabs(targ1) < 0.1))) {
    /* so long as we're not inverted...
       also make sure v0 is the right distance from the average point */
    cur = length3f(d0);
    normalize3f(d0);
    dev = cur - targ2;
    result2 = (float) fabs(dev);
    if(result2 > R_SMALL4) {
      sc = wt * dev * 2.0F;
      scale3f(d0, sc, push);
      add3f(push, p0, p0);
      scale3f(push, 0.333333F, push);
      subtract3f(p1, push, p1);
      subtract3f(p2, push, p2);
      subtract3f(p3, push, p3);
    }
  }

  return result1 + result2;
}
Exemplo n.º 3
0
float ShakerGetPyra(float *targ2, float *v0, float *v1, float *v2, float *v3)
{
  float d0[3], cp[3], d2[3], d3[3];
  float av[3], t0[3];

  add3f(v1, v2, av);
  subtract3f(v2, v1, d2);
  add3f(v3, av, av);
  subtract3f(v3, v1, d3);
  subtract3f(av, v0, t0);
  cross_product3f(d2, d3, cp);
  scale3f(av, 0.33333333F, av);
  normalize3f(cp);
  subtract3f(av, v0, d0);

  (*targ2) = length3f(d0);
  return (dot_product3f(d0, cp));
}
Exemplo n.º 4
0
static void RepValence(CGO *cgo, bool s1, bool s2, bool isRamped, float *v1, float *v2, int *other,
                       int a1, int a2, float *coord, float *color1, float *color2, int ord,
                       float tube_size, int fancy, unsigned int b1, unsigned int b2, int a, bool b1masked, bool b2masked)
{

  float d[3], t[3], p0[3], p1[3], p2[3];
  int a3;
  const float indent = tube_size;
  /* direction vector */
  subtract3f(v2, v1, p0);
  copy3f(p0, d);
  normalize3f(p0);
  /* need a prioritized third atom to get planarity */
  a3 = ObjectMoleculeGetPrioritizedOther(other, a1, a2, NULL);
  if(a3 < 0) {
    t[0] = p0[0];
    t[1] = p0[1];
    t[2] = -p0[2];
  } else {
    subtract3f(coord + 3 * a3, v1, t);
    normalize3f(t);
  }
  cross_product3f(d, t, p1);
  normalize3f(p1);
  if(length3f(p1) == 0.0) {
    p1[0] = p0[1];
    p1[1] = p0[2];
    p1[2] = p0[0];
    cross_product3f(p0, p1, p2);
    normalize3f(p2);
  } else {
    cross_product3f(d, p1, p2);
    normalize3f(p2);
  }
  /* now we have a coordinate system */
  mult3f(p2, tube_size, t);

  bool ord3 = (ord == 3);
  if (ord3)
    mult3f(t, 2.f, t);
  if (fancy || ord3){
    RepLine(cgo, s1, s2, isRamped, v1, v2, color1, b1, b2, a, color2, b1masked, b2masked);
  }
  if(fancy) {
    float f[] = { indent, 1.f - indent };
    float f_1[] = { 1.f - f[0], 1.f - f[1] };
    float vv1[] = { (f_1[0] * v1[0] + f[0] * v2[0]) - 2 * t[0],
                    (f_1[0] * v1[1] + f[0] * v2[1]) - 2 * t[1],
                    (f_1[0] * v1[2] + f[0] * v2[2]) - 2 * t[2] };
    float vv2[] = { (f_1[1] * v1[0] + f[1] * v2[0]) - 2 * t[0],
                    (f_1[1] * v1[1] + f[1] * v2[1]) - 2 * t[1],
                    (f_1[1] * v1[2] + f[1] * v2[2]) - 2 * t[2] };
    RepLine(cgo, s1, s2, isRamped, vv1, vv2, color1, b1, b2, a, color2, b1masked, b2masked);
  } else {
    float vv1[][3] = { { v1[0] - t[0], v1[1] - t[1], v1[2] - t[2] },
                       { v1[0] + t[0], v1[1] + t[1], v1[2] + t[2] } };
    float vv2[][3] = { { v2[0] - t[0], v2[1] - t[1], v2[2] - t[2] },
                       { v2[0] + t[0], v2[1] + t[1], v2[2] + t[2] } };
    RepLine(cgo, s1, s2, isRamped, vv1[0], vv2[0], color1, b1, b2, a, color2, b1masked, b2masked);
    RepLine(cgo, s1, s2, isRamped, vv1[1], vv2[1], color1, b1, b2, a, color2, b1masked, b2masked);
  }
}
Exemplo n.º 5
0
static void RepAromatic(CGO *cgo, bool s1, bool s2, bool isRamped, float *v1, float *v2, int *other,
                        int a1, int a2, float *coord, float *color1, float *color2,
                        float tube_size, int half_state, unsigned int b1, unsigned int b2, int a, bool b1masked, bool b2masked)
{
  float d[3], t[3], p0[3], p1[3], p2[3], *vv;
  int a3;
  int double_sided;

  /* direction vector */
  p0[0] = (v2[0] - v1[0]);
  p0[1] = (v2[1] - v1[1]);
  p0[2] = (v2[2] - v1[2]);
  copy3f(p0, d);
  normalize3f(p0);

  /* need a prioritized third atom to get planarity */
  a3 = ObjectMoleculeGetPrioritizedOther(other, a1, a2, &double_sided);
  if(a3 < 0) {
    t[0] = p0[0];
    t[1] = p0[1];
    t[2] = -p0[2];
  } else {
    vv = coord + 3 * a3;
    t[0] = *(vv++) - v1[0];
    t[1] = *(vv++) - v1[1];
    t[2] = *(vv++) - v1[2];
    normalize3f(t);
  }
  cross_product3f(d, t, p1);
  normalize3f(p1);
  if(length3f(p1) == 0.0) {
    p1[0] = p0[1];
    p1[1] = p0[2];
    p1[2] = p0[0];
    cross_product3f(p0, p1, p2);
    normalize3f(p2);
  } else {
    cross_product3f(d, p1, p2);
    normalize3f(p2);
  }

    t[0] = p2[0] * tube_size * 2;
    t[1] = p2[1] * tube_size * 2;
    t[2] = p2[2] * tube_size * 2;
  RepLine(cgo, s1, s2, isRamped, v1, v2, color1, b1, b2, a, color2, b1masked, b2masked);
  if (s1){
    CGOColorv(cgo, color1);
    CGOPickColor(cgo, b1, b1masked ? cPickableNoPick : a);
    float f[] = { 0.14F, 0.4F } ;
    float f_1[] = { 1.0F - f[0], 1.0F - f[1] };
    float pt1[] = { (f_1[0] * v1[0] + f[0] * v2[0]),
                    (f_1[0] * v1[1] + f[0] * v2[1]),
                    (f_1[0] * v1[2] + f[0] * v2[2]) };
    float pt2[] = { (f_1[1] * v1[0] + f[1] * v2[0]),
                    (f_1[1] * v1[1] + f[1] * v2[1]),
                    (f_1[1] * v1[2] + f[1] * v2[2]) };
    float p1[3], p2[3];
    subtract3f(pt1, t, p1);
    subtract3f(pt2, t, p2);
    cgo->add<cgo::draw::line>(p1, p2);
    if(double_sided) {
      add3f(pt1, t, p1);
      add3f(pt2, t, p2);
      cgo->add<cgo::draw::line>(p1, p2);
    }
  }
  if (s2){
    CGOColorv(cgo, color2);
    CGOPickColor(cgo, b2, b2masked ? cPickableNoPick : a);
    float f[] = { 0.6F, 0.86F } ;
    float f_1[] = { 1.0F - f[0], 1.0F - f[1] };
    float pt1[] = { (f_1[0] * v1[0] + f[0] * v2[0]),
                    (f_1[0] * v1[1] + f[0] * v2[1]),
                    (f_1[0] * v1[2] + f[0] * v2[2]) };
    float pt2[] = { (f_1[1] * v1[0] + f[1] * v2[0]),
                    (f_1[1] * v1[1] + f[1] * v2[1]),
                    (f_1[1] * v1[2] + f[1] * v2[2]) };
    float p1[3], p2[3];
    subtract3f(pt1, t, p1);
    subtract3f(pt2, t, p2);
    cgo->add<cgo::draw::line>(p1, p2);
    if(double_sided) {
      add3f(pt1, t, p1);
      add3f(pt2, t, p2);
      cgo->add<cgo::draw::line>(p1, p2);
    }
  }
}
Exemplo n.º 6
0
float ShakerDoPlan(float *v0, float *v1, float *v2, float *v3,
                   float *p0, float *p1, float *p2, float *p3,
                   float target, int fixed, float wt)
{

  float result;

  float d01[3], d12[3], d23[3], d03[3], cp0[3], cp1[3], dp, sc, dev, d0[3], push[3];
  double s01, s12, s23, s03;

  subtract3f(v0, v1, d01);
  subtract3f(v1, v2, d12);
  subtract3f(v2, v3, d23);
  subtract3f(v0, v3, d03);

  s03 = lengthsq3f(d03);
  s01 = lengthsq3f(d01);
  s12 = lengthsq3f(d12);
  s23 = lengthsq3f(d23);

  if((s03 < s01) || (s03 < s12) || (s03 < s23))
    return 0.0F;

  cross_product3f(d01, d12, cp0);
  cross_product3f(d12, d23, cp1);

  normalize3f(cp0);
  normalize3f(cp1);

  dp = dot_product3f(cp0, cp1);

  result = (dev = 1.0F - (float) fabs(dp));

  if(dev > R_SMALL4) {

    /*
       add3f(cp0,cp1,d0);
       normalize3f(d0);

       cross_product3f(cp0,d12,pos);
       dp2 = dot_product3f(cp1,pos);
     */

    if(fixed && (dp * target < 0.0F)) {

      /* fixed & backwards... */

      if(dp < 0.0F) {
        sc = -wt * dev * 0.5F;
      } else {
        sc = wt * dev * 0.5F;
      }
      sc *= 0.02F;              /* weaken considerably to allow resolution of
                                   inconsistencies (folded rings, etc.) */

    } else if(dp > 0) {
      sc = -wt * dev * 0.5F;
    } else {
      sc = wt * dev * 0.5F;
    }

    if(fixed && (fixed < 7)) {
      /* in small rings, ramp up the planarity factor */
      sc *= 8;
    } else {
      sc *= 0.2F;
    }

    /* pair-wise nudges */

    subtract3f(v0, v3, d0);
    normalize3f(d0);
    scale3f(d0, sc, push);
    add3f(push, p0, p0);
    subtract3f(p3, push, p3);

    subtract3f(v1, v2, d0);
    normalize3f(d0);
    scale3f(d0, sc, push);
    add3f(push, p1, p1);
    subtract3f(p2, push, p2);

    sc = -sc;
    subtract3f(v0, v2, d0);
    normalize3f(d0);
    scale3f(d0, sc, push);
    add3f(push, p0, p0);
    subtract3f(p2, push, p2);

    subtract3f(v1, v3, d0);
    normalize3f(d0);
    scale3f(d0, sc, push);
    add3f(push, p1, p1);
    subtract3f(p3, push, p3);

  } else {
    result = 0.0;
  }
  return result;

}