AngleCmd.h 2.33 KB
Newer Older
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
//
// AngleCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: AngleCmd.h,v 1.3 2008-02-12 05:39:19 fgygi Exp $
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#ifndef ANGLECMD_H
#define ANGLECMD_H

#include <iostream>
#include "UserInterface.h"
#include "Sample.h"
#include <cstdlib>

class AngleCmd : public Cmd
{
  public:

  Sample *s;

  AngleCmd(Sample *sample) : s(sample) {};

  char *name(void) const { return "angle"; }
  char *help_msg(void) const
  {
27
    return
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    "\n angle\n\n"
    " syntax: angle name1 name2 name3\n\n"
    "   The angle command prints the angle defined by three atoms.\n\n";
  }

  int action(int argc, char **argv)
  {
    if ( argc != 4 )
    {
      if ( ui->onpe0() )
      {
        cout << " use: angle name1 name2 name3" << endl;
      }
      return 1;
    }
43
44
45
46
47
48
49
50
51

    string name1(argv[1]);
    string name2(argv[2]);
    string name3(argv[3]);
    Atom* a1 = s->atoms.findAtom(name1);
    Atom* a2 = s->atoms.findAtom(name2);
    Atom* a3 = s->atoms.findAtom(name3);
    if ( a1 == 0 || a2 == 0 || a3 == 0 )
    {
52
53
54
      if ( ui->onpe0() )
      {
        if ( a1 == 0 )
55
          cout << " AngleCmd: atom " << name1 << " not defined" << endl;
56
        if ( a2 == 0 )
57
          cout << " AngleCmd: atom " << name2 << " not defined" << endl;
58
        if ( a3 == 0 )
59
          cout << " AngleCmd: atom " << name3 << " not defined" << endl;
60
61
62
      }
      return 1;
    }
63
64
65

    if ( a1 == a2 || a2 == a3 || a3 == a1 )
    {
66
67
      if ( ui->onpe0() )
      {
68
69
        cout << " AngleCmd: replicated atoms in " << name1
             << " " << name2 << " " << name3 << endl;
70
71
72
      }
      return 1;
    }
73

74
75
76
    D3vector r12(a1->position()-a2->position());
    D3vector r32(a3->position()-a2->position());
    if ( norm(r12) == 0.0 || norm(r32) == 0.0 )
77
    {
78
79
      if ( ui->onpe0() )
      {
80
        cout << " AngleCmd: atoms are too close" << endl;
81
82
83
      }
      return 1;
    }
84

85
86
87
88
89
90
    const double sp = normalized(r12) * normalized(r32);
    const double c = max(-1.0,min(1.0,sp));
    const double a = (180.0/M_PI)*acos(c);
    if ( ui->onpe0() )
    {
      cout.setf(ios::fixed,ios::floatfield);
91
      cout << " angle " << name1 << "-" << name2  << "-" << name3
92
93
           << ": "
           << setprecision(3)
94
           << a << " (deg)" << endl;
95
96
97
98
99
    }
    return 0;
  }
};
#endif