此代码用于对两个 xyz 坐标文件(即 C 0.0 0.1 0.2 这种形式的)进行线性插值。对于几何构型优化问题,如果很难得到最优结构,则可以使用目标结构的两个相邻结构进行线性插值,从而得到最优结构的较好的初始猜测。
程序总共有三个代码文件组成。类的实现没有写成单独的文件。程序会输出 Geom_#.xyz 这样一系列插值结构文件。
---------- DispVec.h ----------
/*
* Displacement vector definition
*/
#ifndef DISPLACEMENT_VECTOR_H
#define DISPLACEMENT_VECTOR_H
#include <iostream>
#include <stdexcept>
#include <iomanip>
class DispVec
{
public:
DispVec() {}
DispVec(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
DispVec(const DispVec& rhs)
{
X = rhs.X;
Y = rhs.Y;
Z = rhs.Z;
}
DispVec& operator=(const DispVec& rhs)
{
if(this != &rhs)
{
X = rhs.X;
Y = rhs.Y;
Z = rhs.Z;
}
return *this;
}
friend DispVec operator-(const DispVec& lhs, const DispVec& rhs)
{
DispVec result;
result.X = lhs.X - rhs.X;
result.Y = lhs.Y - rhs.Y;
result.Z = lhs.Z - rhs.Z;
return result;
}
friend DispVec operator+(const DispVec& lhs, const DispVec& rhs)
{
DispVec result;
result.X = lhs.X + rhs.X;
result.Y = lhs.Y + rhs.Y;
result.Z = lhs.Z + rhs.Z;
return result;
}
DispVec& operator+=(const DispVec& rhs)
{
X += rhs.X;
Y += rhs.Y;
Z += rhs.Z;
return *this;
}
DispVec& operator-=(const DispVec& rhs)
{