MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
kcluster.hpp
1//
2// kcluster.hpp
3//
4// Copyright (C) 2013 Drew Lewis
5//
6// Authors: Drew Lewis
7// Maintainer: Drew Lewis and Edward Valeev
8//
9// This file is part of the MPQC Toolkit.
10//
11// The MPQC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The MPQC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the MPQC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifndef CHEMISTRY_QC_BASIS_KCLUSTER_HPP
29#define CHEMISTRY_QC_BASIS_KCLUSTER_HPP
30
31#include <chemistry/molecule/atom.h>
32#include <chemistry/qc/basis/gaussbas.h>
33#include <Eigen/Dense>
34#include <vector>
35
36namespace mpqc {
37namespace TA{
38 namespace cluster {
39 // A wrapper around sc::Atom which also knows the atoms index in the
40 // molecule.
41 class ClusterAtom : public sc::Atom {
42 public:
43
44 // Takes the atom we want along with its molecular index.
45 ClusterAtom(const sc::Atom &atom, std::size_t index) :
46 sc::Atom(atom),
47 mol_index_(index)
48 {}
49
50 // return the index of the atom in the molecule.
51 std::size_t mol_index() const {return mol_index_;}
52
53 private:
54 // Don't use the default constructor
56
57 std::size_t mol_index_;
58 }; // class ClusterAtom
59 } // namespace cluster
60
65 class KCluster {
66 public:
68 using Vector3 = Eigen::Vector3d;
69
74 KCluster(const Vector3 &pos = Vector3(0,0,0)) : center_(pos), atoms_()
75 {}
76
77 KCluster& operator=(const KCluster &rhs){
78 center_ = rhs.center_;
79 return *this;
80 }
81
83 void add_atom(const sc::Atom &atom, std::size_t index){
84 atoms_.push_back(Atom(atom, index));
85 }
86
88 void add_atom(const Atom &atom){
89 atoms_.push_back(atom);
90 }
91
93 double distance(const Atom &atom){
94 Vector3 atom_vec(atom.r(0), atom.r(1), atom.r(2));
95 // Computes the length of the vector to the atom from the center.
96 return (atom_vec - center_).norm();
97 }
99 const Vector3& center() const { return center_; }
100
101
103 Vector3 centroid(){
104
105 std::size_t n_atoms = natoms();
106 Vector3 centroid(0,0,0);
107
108 // Loop over all of the members of the cluster and total their
109 // positions in each diminsion.
110 for(auto i = 0; i < n_atoms; ++i){
111 centroid[0] += atoms_[i].r(0);
112 centroid[1] += atoms_[i].r(1);
113 centroid[2] += atoms_[i].r(2);
114 }
115
116 // Get the average position in each dimension.
117 centroid[0] = centroid[0]/n_atoms;
118 centroid[1] = centroid[1]/n_atoms;
119 centroid[2] = centroid[2]/n_atoms;
120
121 return centroid;
122
123 }
124
127 std::sort(atoms_.begin(), atoms_.end(), [](const Atom &a,
128 const Atom &b){ return a.mol_index() < b.mol_index();}
129 );
130 }
131
134 center_ = centroid();
135 atoms_.clear();
136 }
137
139
141 std::size_t natoms(){
142 return atoms_.size();
143 }
144
145 const std::vector<Atom>& atoms() const { return atoms_;}
146
147 private:
148 Vector3 center_;
149 std::vector<Atom> atoms_;
150 }; // KCluster
151
152} // namespace TA
153} // namespace mpqc
154
155
156#endif /* CHEMISTRY_QC_BASIS_KCLUSTER_HPP */
class holds the information about the differnt clusters in k-means tiling.
Definition kcluster.hpp:65
std::size_t natoms()
Return the index.
Definition kcluster.hpp:141
KCluster(const Vector3 &pos=Vector3(0, 0, 0))
Constructor takes an Eigen::Vector3d which designates the center of the cluster.
Definition kcluster.hpp:74
const Vector3 & center() const
Returns the position vector of the center of the cluster.
Definition kcluster.hpp:99
void add_atom(const sc::Atom &atom, std::size_t index)
Adds an atom to the cluster. Must know its index as well.
Definition kcluster.hpp:83
Vector3 centroid()
Returns the centorid of the cluster.
Definition kcluster.hpp:103
void sort_atoms()
Sort the atoms so they are ordered by molecule index.
Definition kcluster.hpp:126
void add_atom(const Atom &atom)
Adds an atom to the cluster. Must know its index as well.
Definition kcluster.hpp:88
double distance(const Atom &atom)
Finds distance to any atom to the center of the cluster.
Definition kcluster.hpp:93
void guess_center()
Move the center to the centroid of the cluster and forget members.
Definition kcluster.hpp:133
Definition kcluster.hpp:41
Atom represents an atom in a Molecule.
Definition atom.h:51
double & r(int xyz)
Returns a reference to the x,y, or z coordinate.
Definition atom.h:136
Contains new MPQC code since version 3.
Definition integralenginepool.hpp:37

Generated at Wed Sep 25 2024 02:45:29 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.