Search in sources :

Example 56 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class MainPanel method convertInit.

/**
 * Attempts to load from the supplied data structure
 *
 * @param data Data structure to load from
 * @param file Source file
 * @param commandDescription Description of the command that created this
 * file.
 * @return A thread-based UIDataConverter
 */
private UIDataConverter convertInit(Object data, File file, String commandDescription) {
    if (data == null) {
        return null;
    }
    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String[] patches = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    ConversionFilter convFilter = null;
    // Decide what parser to use.
    if (biojavaDataFilter.accept(data)) {
        convFilter = new BiojavaFilter((Structure) data, newSystem, forceField, properties);
    } else {
        throw new IllegalArgumentException("Not a recognized data structure.");
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeConvFilter = convFilter;
    return new UIDataConverter(data, file, convFilter, this);
}
Also used : ConversionFilter(ffx.potential.parsers.ConversionFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceField(ffx.potential.parameters.ForceField) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) BiojavaFilter(ffx.potential.parsers.BiojavaFilter) Structure(org.biojava.bio.structure.Structure)

Example 57 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class PDBFilter method resolvePolymerLinks.

/**
 * Resolves links between polymeric hetero groups; presently only functional
 * for cyclic molecules.
 *
 * @param molecules List of Molecules in the molecular assembly.
 */
private void resolvePolymerLinks(List<Molecule> molecules) {
    CompositeConfiguration ffProps = forceField.getProperties();
    for (String polyLink : ffProps.getStringArray("polymerlink")) {
        logger.info(" Experimental: linking a cyclic hetero group: " + polyLink);
        // Format: polymerlink resname atom1 atom2 [cyclize]
        String[] toks = polyLink.split("\\s+");
        String resName = toks[0];
        String name1 = toks[1];
        String name2 = toks[2];
        int cyclicLen = 0;
        if (toks.length > 3) {
            cyclicLen = Integer.parseInt(toks[3]);
        }
        Molecule[] matches = molecules.stream().filter((Molecule m) -> m.getResidueName().equalsIgnoreCase(resName)).toArray(Molecule[]::new);
        for (int i = 0; i < matches.length; i++) {
            Molecule mi = matches[i];
            int ii = i + 1;
            if (cyclicLen < 1) {
                logger.severe(" No current support for polymeric, non-cyclic hetero groups");
            // Would probably split by chain.
            } else {
                Molecule next;
                if (ii % cyclicLen == 0) {
                    next = matches[ii - cyclicLen];
                    logger.info(String.format(" Cyclizing molecule %s to %s", mi, next));
                } else {
                    next = matches[ii];
                    logger.info(String.format(" Extending chain from %s to %s.", mi, next));
                }
                Atom from = mi.getAtomByName(name1, true);
                Atom to = next.getAtomByName(name2, true);
                buildBond(from, to);
            }
        }
    }
}
Also used : Molecule(ffx.potential.bonded.Molecule) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Atom(ffx.potential.bonded.Atom)

Example 58 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class PotentialsDataConverter method run.

/**
 * Converts the data structure to MolecularAssembly(s).
 */
@Override
public void run() {
    if (dataStructure == null || dataType.equals(Utilities.DataType.UNK)) {
        throw new IllegalArgumentException("Object passed was not recognized.");
    }
    assemblies = new ArrayList<>();
    propertyList = new ArrayList<>();
    switch(dataType) {
        case BIOJAVA:
            Structure struct = (Structure) dataStructure;
            String name = struct.getPDBCode();
            CompositeConfiguration properties = Keyword.loadProperties(file);
            MolecularAssembly assembly = new MolecularAssembly(name);
            assembly.setFile(file);
            ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
            ForceField forceField = forceFieldFilter.parse();
            assembly.setForceField(forceField);
            BiojavaFilter filter = new BiojavaFilter(struct, assembly, forceField, properties);
            if (filter.convert()) {
                filter.applyAtomProperties();
                assembly.finalize(true, forceField);
                ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
                assembly.setPotential(energy);
                assemblies.add(assembly);
                propertyList.add(properties);
                List<Character> altLocs = filter.getAltLocs();
                if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
                    StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
                    for (Character c : altLocs) {
                        // Do not report the root conformer.
                        if (c == ' ') {
                            continue;
                        }
                        altLocString.append(format("(%s) ", c));
                    }
                    altLocString.append("]\n");
                    logger.info(altLocString.toString());
                }
                /**
                 * Alternate conformers may have different chemistry, so
                 * they each need to be their own MolecularAssembly.
                 */
                for (Character c : altLocs) {
                    if (c.equals(' ') || c.equals('A')) {
                        continue;
                    }
                    MolecularAssembly newAssembly = new MolecularAssembly(name);
                    newAssembly.setForceField(assembly.getForceField());
                    filter.setAltID(newAssembly, c);
                    filter.clearSegIDs();
                    if (filter.convert()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                        properties.addConfiguration(properties);
                    }
                }
            } else {
                logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
            }
            activeAssembly = assembly;
            activeProperties = properties;
            break;
        case UNK:
        default:
            throw new IllegalArgumentException("Object passed was not recognized.");
    }
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) MolecularAssembly(ffx.potential.MolecularAssembly) ForceField(ffx.potential.parameters.ForceField) BiojavaFilter(ffx.potential.parsers.BiojavaFilter) Structure(org.biojava.bio.structure.Structure)

Example 59 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class ForceFieldFilter method parse.

private void parse(CompositeConfiguration properties) {
    try {
        int numConfigs = properties.getNumberOfConfigurations();
        /**
         * Loop over the configurations starting with lowest precedence.
         * This way higher precedence entries will overwrite lower
         * precedence entries within the ForceField instance.
         */
        for (int n = numConfigs - 1; n >= 0; n--) {
            Configuration config = properties.getConfiguration(n);
            Iterator i = config.getKeys();
            while (i.hasNext()) {
                String key = (String) i.next();
                /**
                 * If the key is not recognized as a force field keyword,
                 * continue to the next key.
                 */
                if (!ForceField.isForceFieldKeyword(key)) {
                    continue;
                }
                String[] list = config.getStringArray(key);
                for (String s : list) {
                    // Add back the key to the input line.
                    s = key + " " + s;
                    // Split the line on the pound symbol to remove comments.
                    String input = s.split("#+")[0];
                    String[] tokens = input.trim().split(" +");
                    // Parse keywords.
                    if (parseKeyword(tokens)) {
                        continue;
                    }
                    // Parse force field types.
                    ForceFieldType type;
                    try {
                        type = ForceFieldType.valueOf(key.toUpperCase());
                    } catch (Exception e) {
                        break;
                    }
                    switch(type) {
                        case ATOM:
                            parseAtom(input, tokens);
                            break;
                        case ANGLE:
                            parseAngle(input, tokens);
                            break;
                        case BIOTYPE:
                            parseBioType(input, tokens);
                            break;
                        case BOND:
                            parseBond(input, tokens);
                            break;
                        case CHARGE:
                            parseCharge(input, tokens);
                            break;
                        case MULTIPOLE:
                            parseMultipole(input, tokens);
                            break;
                        case OPBEND:
                            parseOPBend(input, tokens);
                            break;
                        case STRBND:
                            parseStrBnd(input, tokens);
                            break;
                        case PITORS:
                            parsePiTorsion(input, tokens);
                            break;
                        case IMPTORS:
                            parseImproper(input, tokens);
                            break;
                        case TORSION:
                            parseTorsion(input, tokens);
                            break;
                        case TORTORS:
                            parseTorsionTorsion(input, tokens);
                            break;
                        case UREYBRAD:
                            parseUreyBradley(input, tokens);
                            break;
                        case VDW:
                            parseVDW(input, tokens);
                            break;
                        case POLARIZE:
                            parsePolarize(input, tokens);
                            break;
                        case ISOLVRAD:
                            parseISolvRad(input, tokens);
                            break;
                        case RELATIVESOLV:
                            parseRelativeSolvation(input, tokens);
                            break;
                        default:
                            logger.log(Level.WARNING, "ForceField type recognized, but not stored:{0}", type);
                    }
                }
            }
        }
    // forceField.checkPolarizationTypes();
    } catch (Exception e) {
        String message = "Exception parsing force field.";
        logger.log(Level.WARNING, message, e);
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Iterator(java.util.Iterator) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) ForceFieldType(ffx.potential.parameters.ForceField.ForceFieldType) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 60 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project ffx by mjschnie.

the class CrystalReciprocalSpaceTest method test1NSFPermanent.

@Test
public void test1NSFPermanent() {
    String filename = "ffx/xray/structures/1NSF.pdb";
    int index = filename.lastIndexOf(".");
    String name = filename.substring(0, index);
    // load the structure
    ClassLoader cl = this.getClass().getClassLoader();
    File structure = new File(cl.getResource(filename).getPath());
    // load any properties associated with it
    CompositeConfiguration properties = Keyword.loadProperties(structure);
    Crystal crystal = new Crystal(115.996, 115.996, 44.13, 90.0, 90.0, 120.0, "P6");
    Resolution resolution = new Resolution(1.89631);
    ReflectionList reflectionList = new ReflectionList(crystal, resolution);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    // associate molecular assembly with the structure, set up forcefield
    MolecularAssembly molecularAssembly = new MolecularAssembly(name);
    molecularAssembly.setFile(structure);
    molecularAssembly.setForceField(forceField);
    PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
    pdbFile.readFile();
    pdbFile.applyAtomProperties();
    molecularAssembly.finalize(true, forceField);
    ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(molecularAssembly, pdbFile.getCoordRestraints());
    List<Atom> atomList = molecularAssembly.getAtomList();
    Atom[] atomArray = atomList.toArray(new Atom[atomList.size()]);
    // set up FFT and run it
    ParallelTeam parallelTeam = new ParallelTeam();
    CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
    crs.computeAtomicDensity(refinementData.fc);
    // tests
    ComplexNumber b = new ComplexNumber(-496.999, 431.817);
    HKL hkl = reflectionList.getHKL(1, 9, 4);
    ComplexNumber a = refinementData.getFc(hkl.index());
    System.out.println("1 9 4: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("1 9 4 reflection should be correct", -493.7799429881329, a.re(), 0.0001);
    assertEquals("1 9 4 reflection should be correct", 460.7022632345927, a.im(), 0.0001);
    b.re(-129.767);
    b.im(-76.9812);
    hkl = reflectionList.getHKL(5, 26, 8);
    a = refinementData.getFc(hkl.index());
    System.out.println("5 26 8: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("5 26 8 reflection should be correct", -123.05535567943377, a.re(), 0.0001);
    assertEquals("5 26 8 reflection should be correct", -74.59007322382718, a.im(), 0.0001);
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) HKL(ffx.crystal.HKL) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) ReflectionList(ffx.crystal.ReflectionList) ComplexNumber(ffx.numerics.ComplexNumber) Atom(ffx.potential.bonded.Atom) MolecularAssembly(ffx.potential.MolecularAssembly) ForceField(ffx.potential.parameters.ForceField) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution) Test(org.junit.Test)

Aggregations

CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)89 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)46 Test (org.junit.Test)24 ClusterController (org.apache.whirr.ClusterController)22 Configuration (org.apache.commons.configuration.Configuration)21 File (java.io.File)17 Before (org.junit.Before)11 ForceField (ffx.potential.parameters.ForceField)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 BeforeClass (org.junit.BeforeClass)9 IOException (java.io.IOException)8 ClusterSpec (org.apache.whirr.ClusterSpec)8 MolecularAssembly (ffx.potential.MolecularAssembly)7 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)7 PDBFilter (ffx.potential.parsers.PDBFilter)7 MapConfiguration (org.apache.commons.configuration.MapConfiguration)6 Crystal (ffx.crystal.Crystal)5 ReflectionList (ffx.crystal.ReflectionList)5 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)5