CDKではorg.openscience.cdk.graph.matrixパッケージに含まれるAdjacencyMatrixクラスとConnectionMatrixクラスを用いて取得できます。
System.out.println("AdjacencyMatrix");
int am[][] = AdjacencyMatrix.getMatrix(mol);
for(int i=0;i<am.length;i++){
for(int j=0;j<am[i].length;j++){
System.out.print(am[i][j]+" ");
}
System.out.println();
}
System.out.println("\nConnectionMatrix");
double cm[][] = ConnectionMatrix.getMatrix(mol);
for(int i=0;i<cm.length;i++){
for(int j=0;j<cm[i].length;j++){
System.out.print(cm[i][j]+" ");
}
System.out.println();
}
例として、以下の構造を入力してみます。
結果:
AdjacencyMatrix
0 0 0 1 1 1
0 0 0 0 0 1
0 0 0 0 0 1
1 0 0 0 0 0
1 0 0 0 0 0
1 1 1 0 0 0
ConnectionMatrix
0.0 0.0 0.0 1.0 2.0 1.0
0.0 0.0 0.0 0.0 0.0 1.0
0.0 0.0 0.0 0.0 0.0 1.0
1.0 0.0 0.0 0.0 0.0 0.0
2.0 0.0 0.0 0.0 0.0 0.0
1.0 1.0 1.0 0.0 0.0 0.0
隣接行列は、原子同士が結合していれば1を、そうでなければ0を当てはめます。一方、結合行列は、原子同士が結合していれば結合次数を、そうでなければ0を当てはめます。結合行列がdouble型の要素をもつ理由は、aromatic bondなどを1.5と表記したいためです。
人気ブログランキング(クリックして応援してね)