|
| 1 | +/* |
| 2 | + * BioJava development code |
| 3 | + * |
| 4 | + * This code may be freely distributed and modified under the |
| 5 | + * terms of the GNU Lesser General Public Licence. This should |
| 6 | + * be distributed with the code. If you do not have a copy, |
| 7 | + * see: |
| 8 | + * |
| 9 | + * http://www.gnu.org/copyleft/lesser.html |
| 10 | + * |
| 11 | + * Copyright for this code is held jointly by the individual |
| 12 | + * authors. These should be listed in @author doc comments. |
| 13 | + * |
| 14 | + * For more information on the BioJava project and its aims, |
| 15 | + * or to join the biojava-l mailing list, visit the home page |
| 16 | + * at: |
| 17 | + * |
| 18 | + * http://www.biojava.org/ |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +package demo; |
| 23 | + |
| 24 | +import org.biojava.nbio.structure.Chain; |
| 25 | +import org.biojava.nbio.structure.Structure; |
| 26 | +import org.biojava.nbio.structure.io.mmcif.MMcifParser; |
| 27 | +import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; |
| 28 | +import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; |
| 29 | + |
| 30 | +import java.io.BufferedReader; |
| 31 | +import java.io.File; |
| 32 | +import java.io.FileInputStream; |
| 33 | +import java.io.IOException; |
| 34 | +import java.io.InputStreamReader; |
| 35 | +import java.io.PrintWriter; |
| 36 | + |
| 37 | +/** |
| 38 | + * An example of how to convert mmCIF file to PDB file |
| 39 | + * |
| 40 | + * @author Jose Duarte |
| 41 | + * |
| 42 | + */ |
| 43 | +public class DemoMmcifToPdbConverter |
| 44 | +{ |
| 45 | + |
| 46 | + public static void main(String[] args) throws Exception { |
| 47 | + |
| 48 | + File inFile = new File(args[0]); |
| 49 | + File outFile = new File(args[1]); |
| 50 | + convert(inFile, outFile); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + public static void convert(File inFile, File outFile) throws IOException { |
| 56 | + |
| 57 | + MMcifParser parser = new SimpleMMcifParser(); |
| 58 | + |
| 59 | + SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); |
| 60 | + parser.addMMcifConsumer(consumer); |
| 61 | + parser.parse(new BufferedReader(new InputStreamReader(new FileInputStream(inFile)))); |
| 62 | + |
| 63 | + // now get the protein structure. |
| 64 | + Structure cifStructure = consumer.getStructure(); |
| 65 | + |
| 66 | + // and write it out as PDB format |
| 67 | + PrintWriter pr = new PrintWriter(outFile); |
| 68 | + for (Chain c : cifStructure.getChains()) { |
| 69 | + // we can override the chain name, the mmCIF chain names might have more than 1 character |
| 70 | + c.setName(c.getName().substring(0, 1)); |
| 71 | + pr.print(c.toPDB()); |
| 72 | + pr.println("TER"); |
| 73 | + } |
| 74 | + |
| 75 | + pr.close(); |
| 76 | + |
| 77 | + |
| 78 | + } |
| 79 | +} |
0 commit comments