001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package demo;
023
024import org.biojava.nbio.structure.Chain;
025import org.biojava.nbio.structure.Structure;
026import org.biojava.nbio.structure.io.cif.CifStructureConverter;
027
028import java.io.File;
029import java.io.IOException;
030import java.io.PrintWriter;
031
032/**
033 * An example of how to convert mmCIF file to PDB file
034 *
035 * @author Jose Duarte
036 */
037public class DemoMmcifToPdbConverter {
038        public static void main(String[] args) throws Exception {
039                File inFile = new File(args[0]);
040                File outFile = new File(args[1]);
041                convert(inFile, outFile);
042        }
043
044        public static void convert(File inFile, File outFile) throws IOException {
045                // now get the protein structure.
046                Structure cifStructure = CifStructureConverter.fromPath(inFile.toPath());
047
048                // and write it out as PDB format
049                PrintWriter pr = new PrintWriter(outFile);
050                for (Chain c : cifStructure.getChains()) {
051                                // we can override the chain name, the mmCIF chain names might have more than 1 character
052                                c.setName(c.getName().substring(0, 1));
053                                pr.print(c.toPDB());
054                                pr.println("TER");
055                }
056
057                pr.close();
058        }
059}