~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/math/qm/AngularMomentum.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $RCSfile$
 
2
 * $Author: egonw $
 
3
 * $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
4
 * $Revision: 7636 $
 
5
 * 
 
6
 * Copyright (C) 2001-2007  The Chemistry Development Kit (CDK) project
 
7
 * 
 
8
 * Contact: cdk-devel@lists.sf.net
 
9
 * 
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Lesser General Public License
 
12
 * as published by the Free Software Foundation; either version 2.1
 
13
 * of the License, or (at your option) any later version.
 
14
 * All we ask is that proper credit is given for our work, which includes
 
15
 * - but is not limited to - adding the above copyright notice to the beginning
 
16
 * of your source code files, and to any copyright notice that you may distribute
 
17
 * with programs based on this work.
 
18
 * 
 
19
 * This program is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU Lesser General Public License for more details.
 
23
 * 
 
24
 * You should have received a copy of the GNU Lesser General Public License
 
25
 * along with this program; if not, write to the Free Software
 
26
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
27
 *  
 
28
 */
 
29
package org.openscience.cdk.math.qm;
 
30
 
 
31
import org.openscience.cdk.math.Complex;
 
32
import org.openscience.cdk.math.IMatrix;
 
33
import org.openscience.cdk.math.Matrix;
 
34
import org.openscience.cdk.math.Vector;
 
35
 
 
36
/**
 
37
 * This class is used to calculate angular momentum states
 
38
 * 
 
39
 * @author  Stephan Michels <stephan@vern.chem.tu-berlin.de>
 
40
 * @cdk.created 2001-07-22
 
41
 */ 
 
42
public class AngularMomentum {
 
43
  private double J;
 
44
  private int size;
 
45
  private Matrix basis;
 
46
 
 
47
  public AngularMomentum(double J)
 
48
  {
 
49
    this.J = J;
 
50
    size = (int)Math.round(J*2.0+1.0);
 
51
    basis = new Matrix(size,size);
 
52
    int i,j;
 
53
    for(i=0; i<size; i++)
 
54
      for(j=0; j<size; j++)
 
55
        basis.matrix[i][j] = 0d;
 
56
    for(i=0; i<size; i++)
 
57
      basis.matrix[i][i] = 1d;
 
58
  }
 
59
 
 
60
  /**
 
61
   * Calculates the Ix operator
 
62
   */
 
63
  public IMatrix getIx()
 
64
  { 
 
65
    return (new IMatrix(getIplus().add(getIminus()))).mul(new Complex(0.5,0d));
 
66
  }
 
67
 
 
68
  /**
 
69
   * Calculates the Iy operator
 
70
   */
 
71
  public IMatrix getIy()
 
72
  {
 
73
    return (new IMatrix(getIplus().sub(getIminus()))).mul(new Complex(0d,1d)).mul(new Complex(0.5,0d));
 
74
  }
 
75
 
 
76
  /**
 
77
   * Calculates the Iz operator
 
78
   */
 
79
  public IMatrix getIz()
 
80
  {
 
81
    IMatrix Iz = new IMatrix(size,size);
 
82
    int i,j;
 
83
    for(i=0; i<size; i++)
 
84
      for(j=0; j<size; j++)
 
85
      {
 
86
        Iz.realmatrix[i][j] = 0d;
 
87
        Iz.imagmatrix[i][j] = 0d;
 
88
      }
 
89
    for(i=0; i<size; i++)
 
90
    {
 
91
      Iz.realmatrix[i][i] = J-i;
 
92
      Iz.imagmatrix[i][i] = J-i;
 
93
    }
 
94
    return Iz;
 
95
  }
 
96
 
 
97
  /**
 
98
   * Calculates the I+ operator
 
99
   */
 
100
  public Matrix getIplus()
 
101
  {
 
102
    Matrix Iplus = new Matrix(size,size);
 
103
    int i,j;
 
104
    for(i=0; i<size; i++)
 
105
      for(j=0; j<size; j++)
 
106
        Iplus.matrix[i][j] = 0d;
 
107
    for(i=1; i<size; i++)
 
108
      Iplus.matrix[i-1][i] = Math.sqrt(J*J+J-(J-i+1)*(J-i+1)+(J-i+1));
 
109
    return Iplus;
 
110
  }
 
111
 
 
112
  /**
 
113
   * Calculates the I- operator
 
114
   */
 
115
  public Matrix getIminus()
 
116
  {
 
117
    Matrix Iminus = new Matrix(size,size);
 
118
    int i,j;
 
119
    for(i=0; i<size; i++)
 
120
      for(j=0; j<size; j++)
 
121
        Iminus.matrix[i][j] = 0d;
 
122
    for(i=1; i<size; i++)
 
123
      Iminus.matrix[i][i-1] = Math.sqrt(J*J+J-(J-i)*(J-i)-(J-i));
 
124
    return Iminus;
 
125
  }
 
126
 
 
127
  /**
 
128
   * Calculates a spin vector by a direction specified by theta and phi
 
129
   */
 
130
  public Vector getSpinVector(double theta, double phi)
 
131
  {
 
132
    Vector spinvector = new Vector(3);
 
133
    spinvector.vector[0] = Math.sin(theta)*Math.cos(phi);
 
134
    spinvector.vector[1] = Math.sin(theta)*Math.sin(phi);
 
135
    spinvector.vector[2] = Math.cos(phi);
 
136
    return spinvector;
 
137
  }
 
138
}
 
139