001package org.biojava.nbio.structure.io.cif;
002
003import org.biojava.nbio.structure.Chain;
004import org.biojava.nbio.structure.Structure;
005import org.rcsb.cif.model.CifFile;
006
007import java.util.ArrayList;
008import java.util.List;
009
010/**
011 * Convert a structure to a CifFile.
012 * @author Sebastian Bittrich
013 */
014public class CifStructureSupplierImpl extends AbstractCifFileSupplier<Structure> {
015    @Override
016    public CifFile get(Structure container) {
017        return getInternal(container, collectWrappedAtoms(container));
018    }
019
020    private List<WrappedAtom> collectWrappedAtoms(Structure structure) {
021        List<WrappedAtom> wrappedAtoms = new ArrayList<>();
022
023        for (int modelIndex = 0; modelIndex < structure.nrModels(); modelIndex++) {
024            final int model = modelIndex + 1;
025            for (Chain chain : structure.getChains(modelIndex)) {
026                handleChain(chain, model, wrappedAtoms);
027            }
028        }
029
030        return wrappedAtoms;
031    }
032}