@@ -242,6 +242,16 @@ public String getFileHeader() {
242
242
*/
243
243
@ Override
244
244
public Map <String , Object > getAllCifData () {
245
+ return getAllCifDataType ();
246
+ }
247
+ public Map <String , Object > getAllCifDataType (String ... types ) {
248
+ if (types != null ) {
249
+ if (types .length == 0 )
250
+ types = null ;
251
+ else
252
+ for (int i = 0 ; i < types .length ; i ++)
253
+ types [i ] = fixKey (types [i ]);
254
+ }
245
255
line = "" ;
246
256
String key ;
247
257
Map <String , Object > data = null , data0 = null ;
@@ -259,7 +269,7 @@ public Map<String, Object> getAllCifData() {
259
269
continue ;
260
270
}
261
271
if (key .startsWith ("loop_" )) {
262
- getAllCifLoopData (data );
272
+ getAllCifLoopData (data , types );
263
273
continue ;
264
274
}
265
275
if (key .startsWith ("save_" )) {
@@ -286,7 +296,9 @@ public Map<String, Object> getAllCifData() {
286
296
if (value == null ) {
287
297
System .out .println ("CIF ERROR ? end of file; data missing: " + key );
288
298
} else {
289
- data .put (fixKey (key ), value );
299
+ key = fixKey (key );
300
+ if (types == null || checkKey (types , key ))
301
+ data .put (key , value );
290
302
}
291
303
}
292
304
}
@@ -305,33 +317,49 @@ public Map<String, Object> getAllCifData() {
305
317
}
306
318
307
319
/**
308
- * create our own list of keywords and for each one create a list
309
- * of data associated with that keyword. For example, a list of all
310
- * x coordinates, then a list of all y coordinates, etc.
320
+ * create our own list of keywords and for each one create a list of data
321
+ * associated with that keyword. For example, a list of all x coordinates,
322
+ * then a list of all y coordinates, etc.
311
323
*
312
324
* @param data
313
325
* @throws Exception
314
326
*/
315
327
@ SuppressWarnings ("unchecked" )
316
- private void getAllCifLoopData (Map <String , Object > data ) throws Exception {
328
+ private void getAllCifLoopData (Map <String , Object > data , String [] types )
329
+ throws Exception {
317
330
String key ;
318
331
Lst <String > keyWords = new Lst <String >();
319
332
Object o ;
320
- while ((o = peekToken ()) != null && o instanceof String && ((String ) o ).charAt (0 ) == '_' ) {
333
+ boolean skipping = false ;
334
+ while ((o = peekToken ()) != null && o instanceof String
335
+ && ((String ) o ).charAt (0 ) == '_' ) {
321
336
key = fixKey ((String ) getTokenPeeked ());
322
337
keyWords .addLast (key );
338
+ if (types == null || checkKey (types , key ))
323
339
data .put (key , new Lst <String >());
340
+ else
341
+ skipping = true ;
324
342
}
325
343
columnCount = keyWords .size ();
326
344
if (columnCount == 0 )
327
345
return ;
328
346
isLoop = true ;
347
+ if (skipping )
348
+ skipLoop (false );
349
+ else
329
350
while (getData ())
330
351
for (int i = 0 ; i < columnCount ; i ++)
331
352
((Lst <Object >)data .get (keyWords .get (i ))).addLast (columnData [i ]);
332
353
isLoop = false ;
333
354
}
334
355
356
+ private boolean checkKey (String [] types , String key ) {
357
+ for (int i = 0 ; i < types .length ; i ++)
358
+ if (key .startsWith (types [i ]))
359
+ return true ;
360
+ return false ;
361
+ }
362
+
335
363
@ Override
336
364
public String readLine () {
337
365
try {
@@ -893,6 +921,7 @@ protected Object getQuotedStringOrObject(char ch) {
893
921
} catch (Exception e ) {
894
922
System .out .println ("exception in CifDataParser ; " + e );
895
923
}
924
+ return "[" ;
896
925
case ']' :
897
926
ich ++;
898
927
return "]" ;
0 commit comments