tech.molecules.deep.MolEncoder Maven / Gradle / Ivy
package tech.molecules.deep;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
import tech.molecules.leet.chem.ChemUtils;
import java.util.*;
/**
* Format: Each atom is encoded with the same information:
*
* 1. One-Hot Atom
*
* Information about bonds to all n other atoms. For pair of atom i and j:
* if i and j are the same, or if i and j are not connected: all zeros
* otherwise:
*
* 1.
*
*
*
*
*/
public class MolEncoder {
private StereoMolecule m;
int N = 32;
int[] mappedAtomicNo = new int[] {1,6,7,8,9,15,16,17,35};
Map encoding_AtomOneHot = new HashMap<>();
Map encoding_BondTypeSimple = new HashMap<>();
public MolEncoder() {
init();
}
private void init() {
for(int zi=0;zi();
//encoding_BondTypeSimple.put(Molecule.cBondTypeSingle,oneHot(0,7));
//encoding_BondTypeSimple.put(Molecule.cBondTypeDouble,oneHot(1,7));
//encoding_BondTypeSimple.put(Molecule.cBondTypeTriple,oneHot(2,7));
//encoding_BondTypeSimple.put(Molecule.cBondTypeDelocalized,oneHot(3,7));
//encoding_BondTypeSimple.put(Molecule.cBondTypeUp,oneHot(4,7));
//encoding_BondTypeSimple.put(Molecule.cBondTypeDown,oneHot(5,7));
//encoding_BondTypeSimple.put(Molecule.cBondType,oneHot(6,7));
//encoding_bondTypeSimple.put(Molecule.cBond;
}
public void setMolecule(StereoMolecule m) {
this.m = m;
}
public List encodeMolecule() {
m.ensureHelperArrays(Molecule.cHelperCIP);
int[] permutation = new int[N];
for(int zi=0;zi encodeMolecule(int[] permutation) {
List bs = new ArrayList<>();
for(int zi=0;zi= m.getAtoms()) {
return new BitSet(getAtomEncodingLength() + N * getConnectionEncodingLengthPerConnection());
}
BitSet b_all = new BitSet( getAtomEncodingLength() + N * getConnectionEncodingLengthPerConnection() );
BitSet b_i = encodeAtom( permutation[zi] );
b_all.or( b_i );
for(int zj=0;zj bsi.set(xi));
return bsi;
}
public static void print(List bs, int lengthPerBitSet) {
for(BitSet bsi : bs) {
System.out.print("\n");
for(int zi=0;zi encoded = ei.encodeMolecule();
print(encoded,ei.getAtomEncodingLength()+ei.N*ei.getConnectionEncodingLengthPerConnection());
System.out.println("");
//for(BitSet bi : encoded) {
// System.out.println(bi.toString());
//}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy