All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.molecules.leet.chem.shredder.SynthonUtils Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package tech.molecules.leet.chem.shredder;

import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.hyperspace.SimpleSynthon;
import tech.molecules.leet.chem.QueryFeatureUtils;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

public class SynthonUtils {



    public static int countNonConnectorAtoms(StereoMolecule mi) {
        mi.ensureHelperArrays(Molecule.cHelperNeighbours);
        int count = 0;
        for(int zi=0;zi88?0:1;}
        return count;
    }

    public static BitSet findConnectorAtoms(StereoMolecule mi) {
        BitSet bs = new BitSet();
        mi.ensureHelperArrays(Molecule.cHelperNeighbours);
        for(int zi=0;zi=88) {bs.set(zi);}
        }
        return bs;
    }

    public static void removeConnectors(StereoMolecule m) {
        m.ensureHelperArrays(Molecule.cHelperNeighbours);
        for(int zi=0;zi=88) { m.markAtomForDeletion(zi); }
        }
        m.deleteMarkedAtomsAndBonds();
        m.ensureHelperArrays(Molecule.cHelperCIP);
    }

    /**
     * Creates the connector proximal fragments.
     *
     * NOTE!! In these fragments, ALL CONNECTORS, i.e. all
     * atoms with atomic no inbetween 92 and 99 WILL BE
     * REPLACED BY uranium, i.e. by 92 !!
     *
     * NOTE!! In these fragments, all NARROWING query features will
     *        be removed. (the rationale is, NARROWING query features
     *        can only RESTRICT the set of compounds, so to be
     *        safe we do not want to have this in a pruning
     *        step)
     *
     * @param mi_pre
     * @param connector_region_size
     * @return
     */
    public static StereoMolecule createConnectorProximalFragment(StereoMolecule mi_pre, int connector_region_size, int[] atommap) {
        StereoMolecule mi_conn = new StereoMolecule(mi_pre);

        //mi_conn.removeQueryFeatures(); // !! Remove query features
        // REMOVE ONLY NARROWING QUERY FEATURES:
        QueryFeatureUtils.removeNarrowingQueryFeatures(mi_conn);


        mi_conn.ensureHelperArrays(Molecule.cHelperCIP);
        //mi_conn.getAtoms();
        // create the connector-near fragment:
        // 1. set all connector atoms to uranium, and store the positions:
        List connector_positions = new ArrayList<>();
        for(int zi=0;zi=92&&an<92+SynthonShredder.MAX_CONNECTORS) {
                connector_positions.add(zi);
                mi_conn.setAtomicNo(zi,92);
            }
        }
        // 2. cut out the connector region, TODO: separately for every connector (such that we do not get glued together connis..)
        boolean keep_atoms[] = new boolean[mi_conn.getAtoms()];
        for(int zi=0;zi=0 ){
                    if(path_length<=connector_region_size) {
                        keep_atoms[zi] = true;
                    }
                }
            }
        }
        StereoMolecule mi_cut = new StereoMolecule();
        mi_conn.copyMoleculeByAtoms(mi_cut,keep_atoms,true,atommap);
        mi_cut.ensureHelperArrays(Molecule.cHelperCIP);

        if(false) {
            System.out.println("CPF: " + mi_cut.getIDCode());
        }

        return mi_cut;
    }

    /**
     * Cuts the supplied molecule at specific distance from inner and outer connectors.
     * The positions of the connectors are supplied.
     *
     * @param bdc
     * @param cp_pair_positions
     * @param depthInBondsSynthon
     * @param depthInBondsContext
     * @return
     */
    public static StereoMolecule cutBidirectionalContext(StereoMolecule bdc, int cp_pair_positions[][] , int depthInBondsSynthon, int depthInBondsContext, int[] map_old_to_new) {
        StereoMolecule all_prs = new StereoMolecule();
        all_prs.setFragment(true);

        if(map_old_to_new!=null) {
            for(int zi=0;zi=0  && path_length_inner=0  && path_length_outerzi) {
                    if(c_amap1[zi]>=0) {
                        //c_amap2[ c_amap1[zi] ] = zi;
                        map_old_to_new[zi] = c_amap2[ c_amap1[zi] ];
                    }
                }
            }
        }
        all_prs.ensureHelperArrays(Molecule.cHelperCIP);
        return all_prs;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy