Search in sources :

Example 1 with BondEnergies

use of de.ipbhalle.metfraglib.additionals.BondEnergies in project MetFragRelaunched by ipb-halle.

the class CombinedMetFragProcess method initialise.

/**
 * init database, peaklist reader, bond energies
 */
private void initialise() {
    /*
		 * set processing status object
		 * stores and returns status of metfrag processing
		 */
    this.processingStatus = new ProcessingStatus(this.globalSettings);
    this.globalSettings.set(VariableNames.PROCESS_STATUS_OBJECT_NAME, this.processingStatus);
    if (this.logger.isTraceEnabled())
        this.logger.trace(this.getClass().getName());
    try {
        if (this.logger.isTraceEnabled())
            this.logger.trace("\tinitialising database " + VariableNames.METFRAG_DATABASE_TYPE_NAME);
        // initialise database
        this.database = (IDatabase) Class.forName(ClassNames.getClassNameOfDatabase((String) this.globalSettings.get(VariableNames.METFRAG_DATABASE_TYPE_NAME))).getConstructor(Settings.class).newInstance(this.globalSettings);
        if (this.logger.isTraceEnabled())
            this.logger.trace("\tinitialising peakListReader " + VariableNames.METFRAG_PEAK_LIST_READER_NAME);
        // init peaklist reader
        this.peakListReader = (IPeakListReader) Class.forName((String) this.globalSettings.get(VariableNames.METFRAG_PEAK_LIST_READER_NAME)).getConstructor(Settings.class).newInstance(this.globalSettings);
        // init bond energies
        BondEnergies bondEnergies = null;
        // from external file if given
        if (this.globalSettings.get(VariableNames.BOND_ENERGY_FILE_PATH_NAME) != null)
            bondEnergies = new BondEnergies((String) this.globalSettings.get(VariableNames.BOND_ENERGY_FILE_PATH_NAME));
        else
            // or use defaults
            bondEnergies = new BondEnergies();
        this.globalSettings.set(VariableNames.BOND_ENERGY_OBJECT_NAME, bondEnergies);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
}
Also used : BondEnergies(de.ipbhalle.metfraglib.additionals.BondEnergies) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) Settings(de.ipbhalle.metfraglib.settings.Settings) MetFragSingleProcessSettings(de.ipbhalle.metfraglib.settings.MetFragSingleProcessSettings) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with BondEnergies

use of de.ipbhalle.metfraglib.additionals.BondEnergies in project MetFragRelaunched by ipb-halle.

the class NewFragmenterLipidScore method getSingleBondEnergy.

protected double getSingleBondEnergy(String symbol1, String symbol2, String type, boolean isAromaticBond) {
    char typeChar = '=';
    if (!isAromaticBond) {
        if (type.equals("SINGLE"))
            typeChar = '-';
        else if (type.equals("DOUBLE"))
            typeChar = '=';
        else if (type.equals("TRIPLE"))
            typeChar = '~';
        else
            typeChar = '-';
    }
    BondEnergies be = (BondEnergies) this.settings.get(VariableNames.BOND_ENERGY_OBJECT_NAME);
    return be.get(new Bond(symbol1, symbol2, typeChar));
}
Also used : BondEnergies(de.ipbhalle.metfraglib.additionals.BondEnergies) Bond(de.ipbhalle.metfraglib.additionals.Bond)

Example 3 with BondEnergies

use of de.ipbhalle.metfraglib.additionals.BondEnergies in project MetFragRelaunched by ipb-halle.

the class CompareSpectraD3JSBean method generateFragmentsForPeakList.

protected java.util.Vector<PeakFragmentImage> generateFragmentsForPeakList(String peaklist, String smiles, String subpath, String randomString) throws Exception {
    String inchi = MoleculeFunctions.getInChIFromSmiles(smiles);
    ICandidate precursorCandidate = new TopDownPrecursorCandidate(inchi, "1");
    precursorCandidate.initialisePrecursorCandidate();
    precursorCandidate.setProperty(VariableNames.MOLECULAR_FORMULA_NAME, inchi.split("/")[1]);
    precursorCandidate.setProperty(VariableNames.SMILES_NAME, smiles);
    precursorCandidate.initialisePrecursorCandidate();
    MetFragGlobalSettings settings = new MetFragGlobalSettings();
    double monoisotopicmass = precursorCandidate.getMolecularFormula().getMonoisotopicMass();
    settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, monoisotopicmass);
    settings.set(VariableNames.PEAK_LIST_STRING_NAME, peaklist);
    settings.set(VariableNames.PEAK_LIST_NAME, new FilteredStringTandemMassPeakListReader(settings).read());
    precursorCandidate.setUseSmiles(true);
    settings.set(VariableNames.CANDIDATE_NAME, precursorCandidate);
    settings.set(VariableNames.BOND_ENERGY_OBJECT_NAME, new BondEnergies());
    settings.set(VariableNames.RELATIVE_MASS_DEVIATION_NAME, Double.parseDouble(this.relativeMassDeviation));
    settings.set(VariableNames.ABSOLUTE_MASS_DEVIATION_NAME, Double.parseDouble(this.absoluteMassDeviation));
    AbstractFragmenterAssignerScorer fas = (AbstractFragmenterAssignerScorer) Class.forName((String) settings.get(VariableNames.METFRAG_ASSIGNER_SCORER_NAME)).getConstructor(Settings.class, ICandidate.class).newInstance(settings, precursorCandidate);
    fas.setCandidate(precursorCandidate);
    fas.initialise();
    fas.calculate();
    fas.assignInterimScoresResults();
    ICandidate scoredCandidate = fas.getCandidates()[0];
    // generate fragments
    java.io.File imageFolderFragments = new java.io.File(this.getRootSessionFolder() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "comparespectra" + Constants.OS_SPECIFIC_FILE_SEPARATOR + "images" + Constants.OS_SPECIFIC_FILE_SEPARATOR + "fragments" + Constants.OS_SPECIFIC_FILE_SEPARATOR + subpath);
    if (imageFolderFragments.exists())
        FileUtils.deleteDirectory(imageFolderFragments);
    imageFolderFragments.mkdirs();
    String sessionId = this.getSessionId();
    java.util.Vector<PeakFragmentImage> imagePathVector = new java.util.Vector<PeakFragmentImage>();
    for (int i = 0; i < scoredCandidate.getMatchList().getNumberElements(); i++) {
        HighlightSubStructureImageGenerator imageGenerator = new HighlightSubStructureImageGenerator();
        int size = 300;
        if (monoisotopicmass > 500)
            size = 400;
        if (monoisotopicmass > 700)
            size = 500;
        imageGenerator.setImageHeight(size);
        imageGenerator.setImageWidth(size);
        RenderedImage image;
        java.io.File imageFile = new java.io.File(imageFolderFragments.getAbsolutePath() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "fragment_" + i + ".png");
        try {
            image = imageGenerator.generateImage(scoredCandidate.getPrecursorMolecule(), scoredCandidate.getMatchList().getElement(i).getBestMatchedFragment());
            ImageIO.write(image, "png", imageFile);
        } catch (Exception e) {
            System.err.println("error generating fragment image");
        }
        imagePathVector.add(new PeakFragmentImage(scoredCandidate.getMatchList().getElement(i).getMatchedPeak().getMass(), this.getURL() + "/files/" + sessionId + "/comparespectra/images/fragments/" + subpath + "/fragment_" + i + ".png?dummy=" + randomString, MathTools.round(((FragmentMassToPeakMatch) scoredCandidate.getMatchList().getElement(i)).getBestMatchFragmentMass())));
    }
    return imagePathVector;
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) BondEnergies(de.ipbhalle.metfraglib.additionals.BondEnergies) TopDownPrecursorCandidate(de.ipbhalle.metfraglib.candidate.TopDownPrecursorCandidate) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) FilteredStringTandemMassPeakListReader(de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader) AbstractFragmenterAssignerScorer(de.ipbhalle.metfraglib.fragmenterassignerscorer.AbstractFragmenterAssignerScorer) RenderedImage(java.awt.image.RenderedImage) HighlightSubStructureImageGenerator(de.ipbhalle.metfraglib.imagegenerator.HighlightSubStructureImageGenerator)

Example 4 with BondEnergies

use of de.ipbhalle.metfraglib.additionals.BondEnergies in project MetFragRelaunched by ipb-halle.

the class NewFragmenterScore method getSingleBondEnergy.

protected double getSingleBondEnergy(String symbol1, String symbol2, String type, boolean isAromaticBond) {
    char typeChar = '=';
    if (!isAromaticBond) {
        if (type.equals("SINGLE"))
            typeChar = '-';
        else if (type.equals("DOUBLE"))
            typeChar = '=';
        else if (type.equals("TRIPLE"))
            typeChar = '~';
        else
            typeChar = '-';
    }
    BondEnergies be = (BondEnergies) this.settings.get(VariableNames.BOND_ENERGY_OBJECT_NAME);
    return be.get(new Bond(symbol1, symbol2, typeChar));
}
Also used : BondEnergies(de.ipbhalle.metfraglib.additionals.BondEnergies) Bond(de.ipbhalle.metfraglib.additionals.Bond)

Aggregations

BondEnergies (de.ipbhalle.metfraglib.additionals.BondEnergies)4 Bond (de.ipbhalle.metfraglib.additionals.Bond)2 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)2 TopDownPrecursorCandidate (de.ipbhalle.metfraglib.candidate.TopDownPrecursorCandidate)1 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)1 AbstractFragmenterAssignerScorer (de.ipbhalle.metfraglib.fragmenterassignerscorer.AbstractFragmenterAssignerScorer)1 HighlightSubStructureImageGenerator (de.ipbhalle.metfraglib.imagegenerator.HighlightSubStructureImageGenerator)1 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)1 FilteredStringTandemMassPeakListReader (de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader)1 MetFragSingleProcessSettings (de.ipbhalle.metfraglib.settings.MetFragSingleProcessSettings)1 Settings (de.ipbhalle.metfraglib.settings.Settings)1 RenderedImage (java.awt.image.RenderedImage)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CDKException (org.openscience.cdk.exception.CDKException)1