11package org .biojava .nbio .structure .io .cif ;
22
3- import org .biojava .nbio .structure .Atom ;
4- import org .biojava .nbio .structure .Chain ;
5- import org .biojava .nbio .structure .Element ;
6- import org .biojava .nbio .structure .EntityType ;
7- import org .biojava .nbio .structure .Group ;
8- import org .biojava .nbio .structure .GroupType ;
9- import org .biojava .nbio .structure .Structure ;
3+ import org .biojava .nbio .structure .*;
104import org .biojava .nbio .structure .xtal .CrystalCell ;
115import org .biojava .nbio .structure .xtal .SpaceGroup ;
126import org .rcsb .cif .CifBuilder ;
2317import java .util .LinkedHashMap ;
2418import java .util .List ;
2519import java .util .Map ;
20+ import java .util .Optional ;
2621import java .util .function .Consumer ;
2722import java .util .stream .Collector ;
23+ import java .util .stream .Collectors ;
2824
2925/**
3026 * Convert a BioJava object to a CifFile.
@@ -41,9 +37,11 @@ protected CifFile getInternal(Structure structure, List<WrappedAtom> wrappedAtom
4137 SpaceGroup spaceGroup = structure .getPDBHeader ().getCrystallographicInfo ().getSpaceGroup ();
4238 // atom_site
4339 Category atomSite = wrappedAtoms .stream ().collect (toAtomSite ());
40+ // entity information
41+ List <EntityInfo > entityInfos = structure .getEntityInfos ();
4442
4543 MmCifBlockBuilder blockBuilder = CifBuilder .enterFile (StandardSchemata .MMCIF )
46- .enterBlock (structure .getPDBCode ());
44+ .enterBlock (structure .getPdbId () == null ? "" : structure . getPdbId (). getId ());
4745
4846 blockBuilder .enterStructKeywords ().enterText ()
4947 .add (String .join (", " , structure .getPDBHeader ().getKeywords ()))
@@ -92,6 +90,49 @@ protected CifFile getInternal(Structure structure, List<WrappedAtom> wrappedAtom
9290 .leaveCategory ();
9391 }
9492
93+ if (entityInfos != null ) {
94+
95+ String [] entityIds = new String [entityInfos .size ()];
96+ String [] entityTypes = new String [entityInfos .size ()];
97+ String [] entityDescriptions = new String [entityInfos .size ()];
98+
99+ for (int i =0 ; i <entityInfos .size (); i ++) {
100+ EntityInfo e = entityInfos .get (i );
101+ entityIds [i ] = Integer .toString (e .getMolId ());
102+ entityTypes [i ] = e .getType ().getEntityType ();
103+ entityDescriptions [i ] = e .getDescription ();
104+ }
105+
106+ String [] polyEntityIds = entityInfos .stream ().filter (e -> e .getType () == EntityType .POLYMER ).map (e -> Integer .toString (e .getMolId ())).collect (Collectors .toList ()).toArray (new String []{});
107+ String [] entitySeqs = entityInfos .stream ().filter (e -> e .getType () == EntityType .POLYMER ).map (e -> e .getChains ().get (0 ).getSeqResSequence ()).collect (Collectors .toList ()).toArray (new String []{});
108+
109+ blockBuilder .enterEntity ()
110+ .enterId ()
111+ .add (entityIds )
112+ .leaveColumn ()
113+
114+ .enterType ()
115+ .add (entityTypes )
116+ .leaveColumn ()
117+
118+ .enterPdbxDescription ()
119+ .add (entityDescriptions )
120+ .leaveColumn ()
121+
122+ .leaveCategory ();
123+
124+ blockBuilder .enterEntityPoly ()
125+ .enterEntityId ()
126+ .add (polyEntityIds )
127+ .leaveColumn ()
128+
129+ .enterPdbxSeqOneLetterCodeCan ()
130+ .add (entitySeqs )
131+ .leaveColumn ()
132+
133+ .leaveCategory ();
134+ }
135+
95136 return blockBuilder .leaveBlock ().leaveFile ();
96137 }
97138
0 commit comments