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 */
021package org.biojava.nbio.structure.io.mmcif;
022
023import org.biojava.nbio.structure.io.mmcif.chem.MetalBondDistance;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027import java.io.InputStream;
028import java.util.*;
029
030import java.util.zip.GZIPInputStream;
031
032/**
033 * Created by andreas on 6/6/16.
034 */
035public class MetalBondParser  {
036
037    private static final Logger logger = LoggerFactory.getLogger(MetalBondParser.class);
038
039    private static final String BONDS_FILE = "org/biojava/nbio/structure/bond_distance_limits.cif.gz";
040
041
042    static Map<String,List<MetalBondDistance>> definitions;
043
044    static {
045         definitions = init();
046    }
047
048
049    public static Map<String,List<MetalBondDistance>> getMetalBondDefinitions(){
050        return definitions;
051
052    }
053
054
055    private static Map<String,List<MetalBondDistance>> init(){
056
057        InputStream inputStream = MetalBondParser.class.getClassLoader().getResourceAsStream(BONDS_FILE);
058
059        if (inputStream == null) {
060            throw new RuntimeException("Could not find resource "+BONDS_FILE+".  This probably means that your biojava.jar file is corrupt or incorrectly built.");
061        }
062
063        try {
064            GZIPInputStream gzIS = new GZIPInputStream(inputStream);
065
066            SimpleMMcifParser parser = new SimpleMMcifParser();
067
068            MetalBondConsumer consumer = new MetalBondConsumer();
069            parser.addMMcifConsumer(consumer);
070
071            parser.parse(gzIS);
072
073            Map<String,List<MetalBondDistance>> defs = consumer.getDefinitions();
074
075            return defs;
076
077        } catch ( Exception e){
078            logger.error(e.getMessage(),e);
079
080        }
081        return null;
082    }
083
084
085
086}