001package org.biojava.nbio.structure.io.cif; 002 003import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; 004import org.rcsb.cif.schema.mm.ChemComp; 005import org.rcsb.cif.schema.mm.ChemCompAtom; 006import org.rcsb.cif.schema.mm.ChemCompBond; 007import org.slf4j.Logger; 008import org.slf4j.LoggerFactory; 009 010/** 011 * Consumes a CCD file to create the {@link ChemicalComponentDictionary}. 012 * @author Sebastian Bittrich 013 */ 014public class ChemCompConsumerImpl implements ChemCompConsumer { 015 private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumerImpl.class); 016 private final ChemicalComponentDictionary dictionary; 017 private String latestChemCompId; 018 019 public ChemCompConsumerImpl() { 020 this.dictionary = new ChemicalComponentDictionary(); 021 } 022 023 @Override 024 public void consumeChemComp(ChemComp c) { 025 org.biojava.nbio.structure.chem.ChemComp chemComp = new org.biojava.nbio.structure.chem.ChemComp(); 026 chemComp.setId(c.getId().get(0)); 027 chemComp.setName(c.getName().get(0)); 028 chemComp.setType(c.getType().get(0)); 029 chemComp.setPdbxType(c.getPdbxType().get(0)); 030 chemComp.setFormula(c.getFormula().get(0)); 031 chemComp.setMonNstdParentCompId(c.getMonNstdParentCompId().get(0)); 032 chemComp.setPdbxSynonyms(c.getPdbxSynonyms().get(0)); 033 chemComp.setPdbxFormalCharge(c.getPdbxFormalCharge().get(0)); 034 chemComp.setPdbxInitialDate(c.getPdbxInitialDate().get(0)); 035 chemComp.setPdbxModifiedDate(c.getPdbxModifiedDate().get(0)); 036 chemComp.setPdbxAmbiguousFlag(c.getPdbxAmbiguousFlag().get(0)); 037 chemComp.setPdbxReleaseStatus(c.getPdbxReleaseStatus().get(0)); 038 chemComp.setPdbxReplacedBy(c.getPdbxReplacedBy().get(0)); 039 chemComp.setPdbxReplaces(c.getPdbxReplaces().get(0)); 040 chemComp.setFormulaWeight(c.getFormulaWeight().get(0)); 041 chemComp.setOneLetterCode(c.getOneLetterCode().get(0)); 042 chemComp.setThreeLetterCode(c.getThreeLetterCode().get(0)); 043 chemComp.setPdbxModelCoordinatesDetails(c.getPdbxModelCoordinatesDetails().get(0)); 044 chemComp.setPdbxModelCoordinatesMissingFlag(c.getPdbxModelCoordinatesMissingFlag().get(0)); 045 chemComp.setPdbxIdealCoordinatesDetails(c.getPdbxIdealCoordinatesDetails().get(0)); 046 chemComp.setPdbxIdealCoordinatesMissingFlag(c.getPdbxIdealCoordinatesMissingFlag().get(0)); 047 chemComp.setPdbxModelCoordinatesDbCode(c.getPdbxModelCoordinatesDbCode().get(0)); 048 chemComp.setPdbxSubcomponentList(c.getPdbxSubcomponentList().get(0)); 049 chemComp.setPdbxProcessingSite(c.getPdbxProcessingSite().get(0)); 050 if (chemComp.getId() == null) { 051 logger.warn("chem comp ID == null {}", c); 052 } 053 latestChemCompId = chemComp.getId(); 054 dictionary.addChemComp(chemComp); 055 } 056 057 @Override 058 public void consumeChemCompAtom(ChemCompAtom atom) { 059 for (int i = 0; i < atom.getRowCount(); i++) { 060 org.biojava.nbio.structure.chem.ChemCompAtom a = new org.biojava.nbio.structure.chem.ChemCompAtom(); 061 a.setCompId(atom.getCompId().get(i)); 062 a.setAtomId(atom.getAtomId().get(i)); 063 a.setAltAtomId(atom.getAltAtomId().get(i)); 064 a.setTypeSymbol(atom.getTypeSymbol().get(i)); 065 a.setCharge(atom.getCharge().get(i)); 066 a.setPdbxAlign(atom.getPdbxAlign().get(i)); 067 a.setPdbxAromaticFlag(atom.getPdbxAromaticFlag().get(i)); 068 a.setPdbxLeavingAtomFlag(atom.getPdbxLeavingAtomFlag().get(i)); 069 a.setPdbxStereoConfig(atom.getPdbxStereoConfig().get(i)); 070 a.setModelCartnX(atom.getModelCartnX().get(i)); 071 a.setModelCartnY(atom.getModelCartnY().get(i)); 072 a.setModelCartnZ(atom.getModelCartnZ().get(i)); 073 a.setPdbxModelCartnXIdeal(atom.getPdbxModelCartnXIdeal().get(i)); 074 a.setPdbxModelCartnYIdeal(atom.getPdbxModelCartnYIdeal().get(i)); 075 a.setPdbxModelCartnZIdeal(atom.getPdbxModelCartnZIdeal().get(i)); 076 a.setPdbxComponentAtomId(atom.getPdbxComponentAtomId().get(i)); 077 a.setPdbxComponentCompId(atom.getPdbxComponentCompId().get(i)); 078 a.setPdbxOrdinal(atom.getPdbxOrdinal().get(i)); 079 dictionary.getChemComp(latestChemCompId).getAtoms().add(a); 080 } 081 } 082 083 @Override 084 public void consumeChemCompBond(ChemCompBond bond) { 085 for (int i = 0; i < bond.getRowCount(); i++) { 086 org.biojava.nbio.structure.chem.ChemCompBond b = new org.biojava.nbio.structure.chem.ChemCompBond(); 087 b.setAtomId1(bond.getAtomId1().get(i)); 088 b.setAtomId2(bond.getAtomId2().get(i)); 089 b.setCompId(bond.getCompId().get(i)); 090 b.setPdbxAromaticFlag(bond.getPdbxAromaticFlag().get(i)); 091 b.setPdbxOrdinal(bond.getPdbxOrdinal().get(i)); 092 b.setPdbxStereoConfig(bond.getPdbxStereoConfig().get(i)); 093 b.setValueOrder(bond.getValueOrder().get(i)); 094 dictionary.getChemComp(latestChemCompId).getBonds().add(b); 095 } 096 } 097 098 @Override 099 public void prepare() { 100 101 } 102 103 @Override 104 public void finish() { 105 106 } 107 108 @Override 109 public ChemicalComponentDictionary getContainer() { 110 return dictionary; 111 } 112}