化合物が流れる動画 (3)

前回の続き。
こんどは、構造の一部のみを"回転"させます。
OpenbabelのRotateメソッドを使ってみます。
回転可能な結合を適当に見つけてきて、
二面角をなす4原子の番号を関数に入力します。
(この番号は、SDFにおける登場順で付けられます)


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>

using namespace std;
using namespace OpenBabel;

#define PI 3.14159265358979323846

void mol_rotate(int a1, int b1, int c1, int d1, int rot_ang, OBMol* comp,
OBConversion* conv, ofstream* comp_out);

int main(int argc,char *argv[]){
ifstream comp_in( argv[1] );
ofstream comp_out( argv[2] );

OBConversion conv;
conv.SetInFormat("SDF");
conv.SetOutFormat("SDF");

OBMol comp;
conv.Read(&comp, &comp_in);

mol_rotate(7, 8, 9, 10, 120, &comp, &conv, &comp_out);
mol_rotate(22, 23, 24, 25, 180, &comp, &conv, &comp_out);
mol_rotate(7, 8, 9, 10, 240, &comp, &conv, &comp_out);

}

void mol_rotate(int a1, int b1, int c1, int d1, int rot_ang, OBMol* comp,
OBConversion* conv, ofstream* comp_out){
OBAtom *a, *b, *c, *d;
a=(*comp).GetAtom(a1);
b=(*comp).GetAtom(b1);
c=(*comp).GetAtom(c1);
d=(*comp).GetAtom(d1);

double ang = (*comp).GetTorsion(a, b, c, d) * PI / 180.0;

for (int i=0; i<=rot_ang; i=i+5) {
double nang= ang + PI / 180 * i;
char name[10];
sprintf(name, "%d", i);
(*comp).SetTorsion(a, b, c, d, nang);
(*comp).SetTitle( name );
(*conv).Write(comp, comp_out);
}
}