Search in sources :

Example 6 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class RefinementEnergy method setLambda.

/**
 * {@inheritDoc}
 */
@Override
public void setLambda(double lambda) {
    for (MolecularAssembly molecularAssembly : molecularAssemblies) {
        ForceFieldEnergy forceFieldEnergy = molecularAssembly.getPotentialEnergy();
        forceFieldEnergy.setLambda(lambda);
    }
    if (data instanceof DiffractionData) {
        XRayEnergy xRayEnergy = (XRayEnergy) dataEnergy;
        xRayEnergy.setLambda(lambda);
    } else if (data instanceof RealSpaceData) {
        RealSpaceEnergy realSpaceEnergy = (RealSpaceEnergy) dataEnergy;
        realSpaceEnergy.setLambda(lambda);
    }
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) RealSpaceData(ffx.realspace.RealSpaceData) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) RealSpaceEnergy(ffx.realspace.RealSpaceEnergy)

Example 7 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class PotentialsFileOpener method run.

/**
 * At present, parses the PDB, XYZ, INT, or ARC file from the constructor
 * and creates MolecularAssembly and properties objects.
 */
@Override
public void run() {
    int numFiles = allFiles.length;
    for (int i = 0; i < numFiles; i++) {
        File fileI = allFiles[i];
        Path pathI = allPaths[i];
        MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
        assembly.setFile(fileI);
        CompositeConfiguration properties = Keyword.loadProperties(fileI);
        ForceFieldFilter 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();
            try {
                patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
            } catch (IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", patch);
            }
            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));
            }
        }
        assembly.setForceField(forceField);
        if (new PDBFileFilter().acceptDeep(fileI)) {
            filter = new PDBFilter(fileI, assembly, forceField, properties);
        } else if (new XYZFileFilter().acceptDeep(fileI)) {
            filter = new XYZFilter(fileI, assembly, forceField, properties);
        } else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
            filter = new INTFilter(fileI, assembly, forceField, properties);
        } else {
            throw new IllegalArgumentException(String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString()));
        }
        /* If on-open mutations requested, add them to filter. */
        if (mutationsToApply != null && !mutationsToApply.isEmpty()) {
            if (!(filter instanceof PDBFilter)) {
                throw new UnsupportedOperationException("Applying mutations during open only supported by PDB filter atm.");
            }
            ((PDBFilter) filter).mutate(mutationsToApply);
        }
        if (filter.readFile()) {
            if (!(filter instanceof PDBFilter)) {
                Utilities.biochemistry(assembly, filter.getAtomList());
            }
            filter.applyAtomProperties();
            assembly.finalize(true, forceField);
            // ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
            ForceFieldEnergy energy;
            if (nThreads > 0) {
                energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
            } else {
                energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
            }
            assembly.setPotential(energy);
            assemblies.add(assembly);
            propertyList.add(properties);
            if (filter instanceof PDBFilter) {
                PDBFilter pdbFilter = (PDBFilter) filter;
                List<Character> altLocs = pdbFilter.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(pathI.toString());
                    newAssembly.setForceField(assembly.getForceField());
                    pdbFilter.setAltID(newAssembly, c);
                    pdbFilter.clearSegIDs();
                    if (pdbFilter.readFile()) {
                        String fileName = assembly.getFile().getAbsolutePath();
                        newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                        filter.applyAtomProperties();
                        newAssembly.finalize(true, assembly.getForceField());
                        // energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
                        if (nThreads > 0) {
                            energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
                        } else {
                            energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
                        }
                        newAssembly.setPotential(energy);
                        assemblies.add(newAssembly);
                    }
                }
            }
        } else {
            logger.warning(String.format(" Failed to read file %s", fileI.toString()));
        }
    }
    activeAssembly = assemblies.get(0);
    activeProperties = propertyList.get(0);
}
Also used : Path(java.nio.file.Path) PDBFileFilter(ffx.potential.parsers.PDBFileFilter) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ForceFieldFilter(ffx.potential.parsers.ForceFieldFilter) ARCFileFilter(ffx.potential.parsers.ARCFileFilter) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) IOException(java.io.IOException) XYZFileFilter(ffx.potential.parsers.XYZFileFilter) MolecularAssembly(ffx.potential.MolecularAssembly) INTFileFilter(ffx.potential.parsers.INTFileFilter) ForceField(ffx.potential.parameters.ForceField) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter) INTFilter(ffx.potential.parsers.INTFilter)

Example 8 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class CrystalReciprocalSpaceTest method test1N7SPermanent.

/**
 * Test of permanent method, of class CrystalReciprocalSpace.
 */
@Test
public void test1N7SPermanent() {
    String filename = "ffx/xray/structures/1N7S.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());
    PotentialsUtils potutil = new PotentialsUtils();
    MolecularAssembly mola = potutil.open(structure);
    CompositeConfiguration properties = mola.getProperties();
    Crystal crystal = new Crystal(39.767, 51.750, 132.938, 90.00, 90.00, 90.00, "P212121");
    Resolution resolution = new Resolution(1.45);
    ReflectionList reflectionList = new ReflectionList(crystal, resolution);
    DiffractionRefinementData refinementData = new DiffractionRefinementData(properties, reflectionList);
    mola.finalize(true, mola.getForceField());
    ForceFieldEnergy energy = mola.getPotentialEnergy();
    List<Atom> atomList = mola.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(-828.584, -922.704);
    HKL hkl = reflectionList.getHKL(1, 1, 4);
    ComplexNumber a = refinementData.getFc(hkl.index());
    System.out.println("1 1 4: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("1 1 4 reflection should be correct", -753.4722104328416, a.re(), 0.0001);
    assertEquals("1 1 4 reflection should be correct", -1012.1341308707799, a.im(), 0.0001);
    b.re(-70.4582);
    b.im(-486.142);
    hkl = reflectionList.getHKL(2, 1, 10);
    a = refinementData.getFc(hkl.index());
    System.out.println("2 1 10: " + a.toString() + " | " + b.toString() + " | " + a.divides(b).toString());
    assertEquals("2 1 10 reflection should be correct", -69.39660884054359, a.re(), 0.0001);
    assertEquals("2 1 10 reflection should be correct", -412.0147625765328, a.im(), 0.0001);
}
Also used : ParallelTeam(edu.rit.pj.ParallelTeam) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) 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) File(java.io.File) PotentialsUtils(ffx.potential.utils.PotentialsUtils) Crystal(ffx.crystal.Crystal) Resolution(ffx.crystal.Resolution) Test(org.junit.Test)

Example 9 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class MolecularDynamics method assemblyInfo.

protected void assemblyInfo() {
    assemblies.stream().parallel().forEach((ainfo) -> {
        MolecularAssembly mola = ainfo.getAssembly();
        CompositeConfiguration aprops = ainfo.props;
        File file = mola.getFile();
        String filename = FilenameUtils.removeExtension(file.getAbsolutePath());
        File archFile = ainfo.archiveFile;
        if (archFile == null) {
            archFile = new File(filename + ".arc");
            ainfo.archiveFile = XYZFilter.version(archFile);
        }
        if (ainfo.pdbFile == null) {
            String extName = FilenameUtils.getExtension(file.getName());
            if (extName.toLowerCase().startsWith("pdb")) {
                ainfo.pdbFile = file;
            } else {
                ainfo.pdbFile = new File(filename + ".pdb");
            }
        }
        if (ainfo.xyzFilter == null) {
            ainfo.xyzFilter = new XYZFilter(file, mola, mola.getForceField(), aprops);
        }
        if (ainfo.pdbFilter == null) {
            ainfo.pdbFilter = new PDBFilter(ainfo.pdbFile, mola, mola.getForceField(), aprops);
        }
    });
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) XYZFilter(ffx.potential.parsers.XYZFilter) File(java.io.File) PDBFilter(ffx.potential.parsers.PDBFilter)

Example 10 with MolecularAssembly

use of ffx.potential.MolecularAssembly in project ffx by mjschnie.

the class PDBFilter method writeFile.

/**
 * <p>
 * writeFile</p>
 *
 * @param saveFile a {@link java.io.File} object.
 * @param append a {@link java.lang.StringBuilder} object.
 * @param printLinear Whether to print atoms linearly or by element
 * @return Success of writing.
 */
public boolean writeFile(File saveFile, boolean append, boolean printLinear) {
    if (Boolean.parseBoolean(System.getProperty("standardizeAtomNames", "false"))) {
        renameAtomsToPDBStandard(activeMolecularAssembly);
    }
    if (saveFile == null) {
        return false;
    }
    if (vdwH) {
        logger.info(" Printing hydrogens to van der Waals centers instead of nuclear locations.");
    }
    if (nSymOp != 0) {
        logger.info(String.format(" Printing atoms with symmetry operator %s\n", activeMolecularAssembly.getCrystal().spaceGroup.getSymOp(nSymOp).toString()));
    }
    /**
     * Create StringBuilders for ATOM, ANISOU and TER records that can be
     * reused.
     */
    StringBuilder sb = new StringBuilder("ATOM  ");
    StringBuilder anisouSB = new StringBuilder("ANISOU");
    StringBuilder terSB = new StringBuilder("TER   ");
    StringBuilder model = null;
    for (int i = 6; i < 80; i++) {
        sb.append(' ');
        anisouSB.append(' ');
        terSB.append(' ');
    }
    FileWriter fw;
    BufferedWriter bw;
    try {
        File newFile = saveFile;
        if (!append) {
            if (!noVersioning) {
                newFile = version(saveFile);
            }
        } else if (modelsWritten >= 0) {
            model = new StringBuilder(String.format("MODEL     %-4d", ++modelsWritten));
            for (int i = 15; i < 80; i++) {
                model.append(' ');
            }
        }
        activeMolecularAssembly.setFile(newFile);
        activeMolecularAssembly.setName(newFile.getName());
        if (logWrites) {
            logger.log(Level.INFO, " Saving {0}", activeMolecularAssembly.getName());
        }
        fw = new FileWriter(newFile, append);
        bw = new BufferedWriter(fw);
        /**
         * Will come before CRYST1 and ATOM records, but after anything
         * written by writeFileWithHeader (particularly X-ray refinement
         * statistics).
         */
        String[] headerLines = activeMolecularAssembly.getHeaderLines();
        for (String line : headerLines) {
            bw.write(String.format("%s\n", line));
        }
        if (model != null) {
            if (!listMode) {
                bw.write(model.toString());
                bw.newLine();
            } else {
                listOutput.add(model.toString());
            }
        }
        // =============================================================================
        // The CRYST1 record presents the unit cell parameters, space group, and Z
        // value. If the structure was not determined by crystallographic means, CRYST1
        // simply provides the unitary values, with an appropriate REMARK.
        // 
        // 7 - 15       Real(9.3)     a              a (Angstroms).
        // 16 - 24       Real(9.3)     b              b (Angstroms).
        // 25 - 33       Real(9.3)     c              c (Angstroms).
        // 34 - 40       Real(7.2)     alpha          alpha (degrees).
        // 41 - 47       Real(7.2)     beta           beta (degrees).
        // 48 - 54       Real(7.2)     gamma          gamma (degrees).
        // 56 - 66       LString       sGroup         Space  group.
        // 67 - 70       Integer       z              Z value.
        // =============================================================================
        Crystal crystal = activeMolecularAssembly.getCrystal();
        if (crystal != null && !crystal.aperiodic()) {
            Crystal c = crystal.getUnitCell();
            if (!listMode) {
                bw.write(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s\n", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10)));
            } else {
                listOutput.add(format("CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %10s", c.a, c.b, c.c, c.alpha, c.beta, c.gamma, padRight(c.spaceGroup.pdbName, 10)));
            }
        }
        // =============================================================================
        // The SSBOND record identifies each disulfide bond in protein and polypeptide
        // structures by identifying the two residues involved in the bond.
        // The disulfide bond distance is included after the symmetry operations at
        // the end of the SSBOND record.
        // 
        // 8 - 10        Integer         serNum       Serial number.
        // 12 - 14        LString(3)      "CYS"        Residue name.
        // 16             Character       chainID1     Chain identifier.
        // 18 - 21        Integer         seqNum1      Residue sequence number.
        // 22             AChar           icode1       Insertion code.
        // 26 - 28        LString(3)      "CYS"        Residue name.
        // 30             Character       chainID2     Chain identifier.
        // 32 - 35        Integer         seqNum2      Residue sequence number.
        // 36             AChar           icode2       Insertion code.
        // 60 - 65        SymOP           sym1         Symmetry oper for 1st resid
        // 67 - 72        SymOP           sym2         Symmetry oper for 2nd resid
        // 74 – 78        Real(5.2)      Length        Disulfide bond distance
        // 
        // If SG of cysteine is disordered then there are possible alternate linkages.
        // wwPDB practice is to put together all possible SSBOND records. This is
        // problematic because the alternate location identifier is not specified in
        // the SSBOND record.
        // =============================================================================
        int serNum = 1;
        Polymer[] polymers = activeMolecularAssembly.getChains();
        if (polymers != null) {
            for (Polymer polymer : polymers) {
                ArrayList<Residue> residues = polymer.getResidues();
                for (Residue residue : residues) {
                    if (residue.getName().equalsIgnoreCase("CYS")) {
                        List<Atom> cysAtoms = residue.getAtomList();
                        Atom SG1 = null;
                        for (Atom atom : cysAtoms) {
                            String atName = atom.getName().toUpperCase();
                            if (atName.equals("SG") || atName.equals("SH")) {
                                SG1 = atom;
                                break;
                            }
                        }
                        List<Bond> bonds = SG1.getBonds();
                        for (Bond bond : bonds) {
                            Atom SG2 = bond.get1_2(SG1);
                            if (SG2.getName().equalsIgnoreCase("SG")) {
                                if (SG1.getIndex() < SG2.getIndex()) {
                                    bond.energy(false);
                                    if (!listMode) {
                                        bw.write(format("SSBOND %3d CYS %1s %4s    CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue()));
                                    } else {
                                        listOutput.add(format("SSBOND %3d CYS %1s %4s    CYS %1s %4s %36s %5.2f\n", serNum++, SG1.getChainID().toString(), Hybrid36.encode(4, SG1.getResidueNumber()), SG2.getChainID().toString(), Hybrid36.encode(4, SG2.getResidueNumber()), "", bond.getValue()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // =============================================================================
        // 
        // 7 - 11        Integer       serial       Atom serial number.
        // 13 - 16        Atom          name         Atom name.
        // 17             Character     altLoc       Alternate location indicator.
        // 18 - 20        Residue name  resName      Residue name.
        // 22             Character     chainID      Chain identifier.
        // 23 - 26        Integer       resSeq       Residue sequence number.
        // 27             AChar         iCode        Code for insertion of residues.
        // 31 - 38        Real(8.3)     x            Orthogonal coordinates for X in Angstroms.
        // 39 - 46        Real(8.3)     y            Orthogonal coordinates for Y in Angstroms.
        // 47 - 54        Real(8.3)     z            Orthogonal coordinates for Z in Angstroms.
        // 55 - 60        Real(6.2)     occupancy    Occupancy.
        // 61 - 66        Real(6.2)     tempFactor   Temperature factor.
        // 77 - 78        LString(2)    element      Element symbol, right-justified.
        // 79 - 80        LString(2)    charge       Charge  on the atom.
        // =============================================================================
        // 1         2         3         4         5         6         7
        // 123456789012345678901234567890123456789012345678901234567890123456789012345678
        // ATOM      1  N   ILE A  16      60.614  71.140 -10.592  1.00  7.38           N
        // ATOM      2  CA  ILE A  16      60.793  72.149  -9.511  1.00  6.91           C
        MolecularAssembly[] molecularAssemblies = this.getMolecularAssemblys();
        int serial = 1;
        // Loop over biomolecular chains
        if (polymers != null) {
            for (Polymer polymer : polymers) {
                currentSegID = polymer.getName();
                currentChainID = polymer.getChainID();
                sb.setCharAt(21, currentChainID);
                // Loop over residues
                ArrayList<Residue> residues = polymer.getResidues();
                for (Residue residue : residues) {
                    String resName = residue.getName();
                    if (resName.length() > 3) {
                        resName = resName.substring(0, 3);
                    }
                    int resID = residue.getResidueNumber();
                    sb.replace(17, 20, padLeft(resName.toUpperCase(), 3));
                    sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID)));
                    // Loop over atoms
                    ArrayList<Atom> residueAtoms = residue.getAtomList();
                    ArrayList<Atom> backboneAtoms = residue.getBackboneAtoms();
                    boolean altLocFound = false;
                    for (Atom atom : backboneAtoms) {
                        writeAtom(atom, serial++, sb, anisouSB, bw);
                        Character altLoc = atom.getAltLoc();
                        if (altLoc != null && !altLoc.equals(' ')) {
                            altLocFound = true;
                        }
                        residueAtoms.remove(atom);
                    }
                    for (Atom atom : residueAtoms) {
                        writeAtom(atom, serial++, sb, anisouSB, bw);
                        Character altLoc = atom.getAltLoc();
                        if (altLoc != null && !altLoc.equals(' ')) {
                            altLocFound = true;
                        }
                    }
                    // Write out alternate conformers
                    if (altLocFound) {
                        for (int ma = 1; ma < molecularAssemblies.length; ma++) {
                            MolecularAssembly altMolecularAssembly = molecularAssemblies[ma];
                            Polymer altPolymer = altMolecularAssembly.getPolymer(currentChainID, currentSegID, false);
                            Residue altResidue = altPolymer.getResidue(resName, resID, false);
                            backboneAtoms = altResidue.getBackboneAtoms();
                            residueAtoms = altResidue.getAtomList();
                            for (Atom atom : backboneAtoms) {
                                if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) {
                                    writeAtom(atom, serial++, sb, anisouSB, bw);
                                }
                                residueAtoms.remove(atom);
                            }
                            for (Atom atom : residueAtoms) {
                                if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) {
                                    writeAtom(atom, serial++, sb, anisouSB, bw);
                                }
                            }
                        }
                    }
                }
                terSB.replace(6, 11, String.format("%5s", Hybrid36.encode(5, serial++)));
                terSB.replace(12, 16, "    ");
                terSB.replace(16, 26, sb.substring(16, 26));
                if (!listMode) {
                    bw.write(terSB.toString());
                    bw.newLine();
                } else {
                    listOutput.add(terSB.toString());
                }
            }
        }
        sb.replace(0, 6, "HETATM");
        sb.setCharAt(21, 'A');
        int resID = 1;
        Polymer polymer = activeMolecularAssembly.getPolymer('A', "A", false);
        if (polymer != null) {
            ArrayList<Residue> residues = polymer.getResidues();
            for (Residue residue : residues) {
                int resID2 = residue.getResidueNumber();
                if (resID2 >= resID) {
                    resID = resID2 + 1;
                }
            }
        }
        /**
         * Loop over molecules, ions and then water.
         */
        ArrayList<Molecule> molecules = activeMolecularAssembly.getMolecules();
        for (int i = 0; i < molecules.size(); i++) {
            Molecule molecule = (Molecule) molecules.get(i);
            Character chainID = molecule.getChainID();
            sb.setCharAt(21, chainID);
            String resName = molecule.getResidueName();
            if (resName.length() > 3) {
                resName = resName.substring(0, 3);
            }
            sb.replace(17, 20, padLeft(resName.toUpperCase(), 3));
            sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID)));
            ArrayList<Atom> moleculeAtoms = molecule.getAtomList();
            boolean altLocFound = false;
            for (Atom atom : moleculeAtoms) {
                writeAtom(atom, serial++, sb, anisouSB, bw);
                Character altLoc = atom.getAltLoc();
                if (altLoc != null && !altLoc.equals(' ')) {
                    altLocFound = true;
                }
            }
            // Write out alternate conformers
            if (altLocFound) {
                for (int ma = 1; ma < molecularAssemblies.length; ma++) {
                    MolecularAssembly altMolecularAssembly = molecularAssemblies[ma];
                    MSNode altmolecule = altMolecularAssembly.getMolecules().get(i);
                    moleculeAtoms = altmolecule.getAtomList();
                    for (Atom atom : moleculeAtoms) {
                        if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) {
                            writeAtom(atom, serial++, sb, anisouSB, bw);
                        }
                    }
                }
            }
            resID++;
        }
        ArrayList<MSNode> ions = activeMolecularAssembly.getIons();
        for (int i = 0; i < ions.size(); i++) {
            Molecule ion = (Molecule) ions.get(i);
            Character chainID = ion.getChainID();
            sb.setCharAt(21, chainID);
            String resName = ion.getResidueName();
            if (resName.length() > 3) {
                resName = resName.substring(0, 3);
            }
            sb.replace(17, 20, padLeft(resName.toUpperCase(), 3));
            sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID)));
            ArrayList<Atom> ionAtoms = ion.getAtomList();
            boolean altLocFound = false;
            for (Atom atom : ionAtoms) {
                writeAtom(atom, serial++, sb, anisouSB, bw);
                Character altLoc = atom.getAltLoc();
                if (altLoc != null && !altLoc.equals(' ')) {
                    altLocFound = true;
                }
            }
            // Write out alternate conformers
            if (altLocFound) {
                for (int ma = 1; ma < molecularAssemblies.length; ma++) {
                    MolecularAssembly altMolecularAssembly = molecularAssemblies[ma];
                    MSNode altion = altMolecularAssembly.getIons().get(i);
                    ionAtoms = altion.getAtomList();
                    for (Atom atom : ionAtoms) {
                        if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) {
                            writeAtom(atom, serial++, sb, anisouSB, bw);
                        }
                    }
                }
            }
            resID++;
        }
        ArrayList<MSNode> waters = activeMolecularAssembly.getWaters();
        for (int i = 0; i < waters.size(); i++) {
            Molecule water = (Molecule) waters.get(i);
            Character chainID = water.getChainID();
            sb.setCharAt(21, chainID);
            String resName = water.getResidueName();
            if (resName.length() > 3) {
                resName = resName.substring(0, 3);
            }
            sb.replace(17, 20, padLeft(resName.toUpperCase(), 3));
            sb.replace(22, 26, String.format("%4s", Hybrid36.encode(4, resID)));
            ArrayList<Atom> waterAtoms = water.getAtomList();
            boolean altLocFound = false;
            for (Atom atom : waterAtoms) {
                writeAtom(atom, serial++, sb, anisouSB, bw);
                Character altLoc = atom.getAltLoc();
                if (altLoc != null && !altLoc.equals(' ')) {
                    altLocFound = true;
                }
            }
            // Write out alternate conformers
            if (altLocFound) {
                for (int ma = 1; ma < molecularAssemblies.length; ma++) {
                    MolecularAssembly altMolecularAssembly = molecularAssemblies[ma];
                    MSNode altwater = altMolecularAssembly.getWaters().get(i);
                    waterAtoms = altwater.getAtomList();
                    for (Atom atom : waterAtoms) {
                        if (atom.getAltLoc() != null && !atom.getAltLoc().equals(' ') && !atom.getAltLoc().equals('A')) {
                            writeAtom(atom, serial++, sb, anisouSB, bw);
                        }
                    }
                }
            }
            resID++;
        }
        String end = model != null ? "ENDMDL" : "END";
        if (!listMode) {
            bw.write(end);
            bw.newLine();
        } else {
            listOutput.add(end);
        }
        bw.close();
    } catch (Exception e) {
        String message = "Exception writing to file: " + saveFile.toString();
        logger.log(Level.WARNING, message, e);
        return false;
    }
    return true;
}
Also used : FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter) MSNode(ffx.potential.bonded.MSNode) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom) MissingHeavyAtomException(ffx.potential.bonded.BondedUtils.MissingHeavyAtomException) IOException(java.io.IOException) MissingAtomTypeException(ffx.potential.bonded.BondedUtils.MissingAtomTypeException) Molecule(ffx.potential.bonded.Molecule) MolecularAssembly(ffx.potential.MolecularAssembly) Residue(ffx.potential.bonded.Residue) Bond(ffx.potential.bonded.Bond) File(java.io.File) Crystal(ffx.crystal.Crystal)

Aggregations

MolecularAssembly (ffx.potential.MolecularAssembly)34 File (java.io.File)13 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)11 Atom (ffx.potential.bonded.Atom)10 Crystal (ffx.crystal.Crystal)7 MSNode (ffx.potential.bonded.MSNode)7 IOException (java.io.IOException)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)5 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)5 Molecule (ffx.potential.bonded.Molecule)5 Polymer (ffx.potential.bonded.Polymer)5 Residue (ffx.potential.bonded.Residue)5 PDBFilter (ffx.potential.parsers.PDBFilter)5 ParallelTeam (edu.rit.pj.ParallelTeam)4 Bond (ffx.potential.bonded.Bond)4 ExtendedSystem (ffx.potential.extended.ExtendedSystem)4 ForceField (ffx.potential.parameters.ForceField)4 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)4 BufferedWriter (java.io.BufferedWriter)4