001    /*
002     * Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    
011    package com.chemaxon.descriptors.fingerprints.pf2d;
012    
013    import com.chemaxon.apidiscovery.annotations.BuilderClass;
014    import com.chemaxon.apidiscovery.annotations.Description;
015    import com.chemaxon.apidiscovery.annotations.Parameter;
016    import com.chemaxon.apidiscovery.annotations.Parametrized;
017    import com.chemaxon.apidiscovery.interfaces.ParameterBuilder;
018    import com.chemaxon.apidiscovery.util.ServiceUtil;
019    import com.chemaxon.common.annotations.PublicAPI;
020    import com.chemaxon.descriptors.common.DescriptorParameters;
021    import com.google.common.annotations.Beta;
022    import com.google.common.base.Optional;
023    
024    /**
025     * Pharmacophore FP parameters class.
026     * <p>
027     * Please note that this class is marked with @Beta annotation, so it can be subject of incompatible changes or removal
028     * in later releases.
029     * </p>
030     * @author Laszlo Antal
031     */
032    @Description(
033            shortName = "PF2D",
034            name = "2D pharmacophore fingerprint (PF2D)",
035            description = "Atom-pair based 2D pharmacophore fingerprints are defined as the collection"
036            + " of all atom-atom pharmacophore feature pairs along with their topological distances."
037            + " These datasets are represented in histograms.")
038    @BuilderClass(builderClass = PfParameters.Builder.class)
039    @Beta
040    @PublicAPI
041    public class PfParameters implements DescriptorParameters {
042    
043        // PARAMETERS ======================================================================================================
044    
045        /**
046         * XML configuration string.
047         */
048        private final Optional<String> xmlConfig;
049    
050        /**
051         * Constructor based on a builder.
052         * @param builder Builder which current state will be represented.
053         */
054        private PfParameters(final Builder builder) {
055            this.xmlConfig = builder.xmlConfig;
056        }
057    
058        /**
059         * Constructor using the default settings.
060         */
061        public PfParameters() {
062            this(new Builder());
063        }
064    
065        /**
066         * Construct a builder for this parameter class, initialized to default.
067         * @return Builder initialized to default settings
068         */
069        public static Builder createNewBuilder() {
070            return new Builder();
071        }
072    
073        @Override
074        public PfGenerator getDescriptorGenerator() {
075            final ConstructPfGenerator c = ServiceUtil.loadService(ConstructPfGenerator.class, true);
076            return c.constructPfGenerator(this);
077        }
078    
079        @Override
080        public String toString() {
081            return "XML config file: " + (this.xmlConfig.isPresent() ? this.xmlConfig.get() : "-");
082        }
083    
084        // GETTERS =========================================================================================================
085    
086        /**
087         * The XML configuration string.
088         * @return config string
089         */
090        public Optional<String> getXmlConfig() {
091            return this.xmlConfig;
092        }
093    
094        // HELPER INTERFACE FOR DI =========================================================================================
095        /**
096         * Interface representing PF generator constructor.
097         */
098        protected interface ConstructPfGenerator {
099            /**
100             * Constructor invocation.
101             * @param parameters Generator parameters
102             * @return Created generator
103             */
104            PfGenerator constructPfGenerator(PfParameters parameters);
105        }
106    
107        // BUILDER CLASS ===================================================================================================
108    
109        /**
110         * Builder class for the immutable parameter object.
111         */
112        @Parametrized
113        public static class Builder implements ParameterBuilder<PfParameters> {
114    
115            // /**
116            // * Fuzzy smoothing factor.
117            // */
118            // @Parameter(order = 1)
119            // @Description(
120            // shortName = "Fuzzy smoothing factor",
121            // name = "Fuzzy smoothing factor",
122            // description = "Smoothing factor used in the construction of fuzzy fingerprints.")
123            // private int fuzzySmoothingFactor;
124    
125            /**
126             * XML configuration file.
127             */
128            @Parameter(order = 1)
129            @Description(shortName = "XML config", name = "XML configuration string", description = "XML configuration string.")
130            private Optional<String> xmlConfig;
131    
132            // /**
133            // * Atom typing.
134            // */
135            // @Parameter(order = 3)
136            // @Description(
137            // shortName = "Atom typing",
138            // name = "Atom typing shourtcut",
139            // description = "Shortcut to predefined atom typing settings to be used.")
140            // private PfAtomTypizers atomTypizer;
141    
142            /**
143             * Constructor with default settings.
144             */
145            public Builder() {
146                this.xmlConfig = Optional.absent();
147            }
148    
149            /**
150             * Constructor based on a parameter object.
151             * @param parameters Parameter object
152             */
153            public Builder(final PfParameters parameters) {
154                this.xmlConfig = parameters.getXmlConfig();
155            }
156    
157            /**
158             * Sets configuration xml string.
159             * @param xmlConfig configuration string
160             * @return reference to this builder
161             */
162            public Builder xmlConfig(final String xmlConfig) {
163                this.xmlConfig = Optional.of(xmlConfig);
164                return this;
165            }
166    
167            /**
168             * Sets configuration xml string.
169             * @param xmlConfig configuration string
170             * @return reference to this builder
171             */
172            public Builder xmlConfig(Optional<String> xmlConfig) {
173                this.xmlConfig = xmlConfig;
174                return this;
175            }
176    
177            @Override
178            public PfParameters build() {
179                return new PfParameters(this);
180            }
181        }
182    }