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.mmcif.MMcifParser;
027import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer;
028import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser;
029
030import java.io.BufferedReader;
031import java.io.File;
032import java.io.FileInputStream;
033import java.io.IOException;
034import java.io.InputStreamReader;
035import java.io.PrintWriter;
036
037/** 
038 * An example of how to convert mmCIF file to PDB file
039 *
040 * @author Jose Duarte
041 *
042 */
043public class DemoMmcifToPdbConverter
044{
045
046        public static void main(String[] args) throws Exception {
047
048                File inFile = new File(args[0]);
049                File outFile = new File(args[1]);
050                convert(inFile, outFile);
051        }
052
053
054
055        public static void convert(File inFile, File outFile) throws IOException {
056                                 
057        MMcifParser parser = new SimpleMMcifParser();
058 
059        SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();       
060        parser.addMMcifConsumer(consumer);
061        parser.parse(new BufferedReader(new InputStreamReader(new FileInputStream(inFile))));
062        
063        // now get the protein structure.
064        Structure cifStructure = consumer.getStructure();
065
066        // and write it out as PDB format
067        PrintWriter pr = new PrintWriter(outFile);
068        for (Chain c : cifStructure.getChains()) {
069                        // we can override the chain name, the mmCIF chain names might have more than 1 character
070                        c.setName(c.getName().substring(0, 1));
071                        pr.print(c.toPDB());
072                        pr.println("TER");
073        }
074        
075                pr.close();
076                
077
078        }
079}