@@ -334,25 +334,25 @@ public static Cell convertCrystalCellToCell(CrystalCell c) {
334334 /**
335335 * Converts an Atom object to an {@link AtomSite} object.
336336 * @param a
337- * @param model
338- * @param chainId
339- * @param internalChainId
337+ * @param model the model number for the output AtomSites
338+ * @param chainName the chain identifier (author id) for the output AtomSites
339+ * @param chainId the internal chain identifier (asym id) for the output AtomSites
340340 * @return
341341 */
342- public static AtomSite convertAtomToAtomSite (Atom a , int model , String chainId , String internalChainId ) {
343- return convertAtomToAtomSite (a , model , chainId , internalChainId , a .getPDBserial ());
342+ public static AtomSite convertAtomToAtomSite (Atom a , int model , String chainName , String chainId ) {
343+ return convertAtomToAtomSite (a , model , chainName , chainId , a .getPDBserial ());
344344 }
345345
346346 /**
347347 * Converts an Atom object to an {@link AtomSite} object.
348- * @param a
349- * @param model
350- * @param chainId
351- * @param internalChainId
348+ * @param a the atom
349+ * @param model the model number for the output AtomSites
350+ * @param chainName the chain identifier (author id) for the output AtomSites
351+ * @param chainId the internal chain identifier (asym id) for the output AtomSites
352352 * @param atomId the atom id to be written to AtomSite
353353 * @return
354354 */
355- public static AtomSite convertAtomToAtomSite (Atom a , int model , String chainId , String internalChainId , int atomId ) {
355+ public static AtomSite convertAtomToAtomSite (Atom a , int model , String chainName , String chainId , int atomId ) {
356356
357357 /*
358358 ATOM 7 C CD . GLU A 1 24 ? -10.109 15.374 38.853 1.00 50.05 ? ? ? ? ? ? 24 GLU A CD 1
@@ -404,7 +404,7 @@ record = "ATOM";
404404 atomSite .setLabel_atom_id (a .getName ());
405405 atomSite .setLabel_alt_id (altLocStr );
406406 atomSite .setLabel_comp_id (g .getPDBName ());
407- atomSite .setLabel_asym_id (internalChainId );
407+ atomSite .setLabel_asym_id (chainId );
408408 atomSite .setLabel_entity_id (entityId );
409409 atomSite .setLabel_seq_id (labelSeqId );
410410 atomSite .setPdbx_PDB_ins_code (insCode );
@@ -415,26 +415,29 @@ record = "ATOM";
415415 atomSite .setB_iso_or_equiv (FileConvert .d2 .format (a .getTempFactor ()));
416416 atomSite .setAuth_seq_id (Integer .toString (g .getResidueNumber ().getSeqNum ()));
417417 atomSite .setAuth_comp_id (g .getPDBName ());
418- atomSite .setAuth_asym_id (chainId );
418+ atomSite .setAuth_asym_id (chainName );
419419 atomSite .setAuth_atom_id (a .getName ());
420420 atomSite .setPdbx_PDB_model_num (Integer .toString (model ));
421421
422422 return atomSite ;
423423 }
424424
425425 /**
426- * Converts a Group into a List of {@link AtomSite} objects
427- * @param g
428- * @param model
429- * @param chainId
430- * @param internalChainId
426+ * Converts a Group into a List of {@link AtomSite} objects.
427+ * Atoms in other altloc groups (different from the main group) are also included, removing possible duplicates
428+ * via using the atom identifier to assess uniqueness.
429+ * @param g the group
430+ * @param model the model number for the output AtomSites
431+ * @param chainName the chain identifier (author id) for the output AtomSites
432+ * @param chainId the internal chain identifier (asym id) for the output AtomSites
431433 * @return
432434 */
433- private static List <AtomSite > convertGroupToAtomSites (Group g , int model , String chainId , String internalChainId ) {
435+ public static List <AtomSite > convertGroupToAtomSites (Group g , int model , String chainName , String chainId ) {
434436
435437 // The alt locs can have duplicates, since at parsing time we make sure that all alt loc groups have
436438 // all atoms (see StructureTools#cleanUpAltLocs)
437439 // Thus we have to remove duplicates here by using the atom id
440+ // See issue https://github.com/biojava/biojava/issues/778 and TestAltLocs.testMmcifWritingAllAltlocs/testMmcifWritingPartialAltlocs
438441 Map <Integer , AtomSite > uniqueAtomSites = new LinkedHashMap <>();
439442
440443 int groupsize = g .size ();
@@ -444,12 +447,12 @@ private static List<AtomSite> convertGroupToAtomSites(Group g, int model, String
444447 if ( a == null )
445448 continue ;
446449
447- uniqueAtomSites .put (a .getPDBserial (), convertAtomToAtomSite (a , model , chainId , internalChainId ));
450+ uniqueAtomSites .put (a .getPDBserial (), convertAtomToAtomSite (a , model , chainName , chainId ));
448451 }
449452
450453 if ( g .hasAltLoc ()){
451454 for (Group alt : g .getAltLocs () ) {
452- for (AtomSite atomSite : convertGroupToAtomSites (alt , model , chainId , internalChainId )) {
455+ for (AtomSite atomSite : convertGroupToAtomSites (alt , model , chainName , chainId )) {
453456 uniqueAtomSites .put (Integer .parseInt (atomSite .getId ()), atomSite );
454457 }
455458 }
@@ -459,15 +462,15 @@ private static List<AtomSite> convertGroupToAtomSites(Group g, int model, String
459462
460463 /**
461464 * Converts a Chain into a List of {@link AtomSite} objects
462- * @param c
463- * @param model
464- * @param authorId
465- * @param asymId
465+ * @param c the chain
466+ * @param model the model number for the output AtomSites
467+ * @param chainName the chain identifier (author id) for the output AtomSites
468+ * @param chainId the internal chain identifier (asym id) for the output AtomSites
466469 * @return
467470 */
468- public static List <AtomSite > convertChainToAtomSites (Chain c , int model , String authorId , String asymId ) {
471+ public static List <AtomSite > convertChainToAtomSites (Chain c , int model , String chainName , String chainId ) {
469472
470- List <AtomSite > list = new ArrayList <AtomSite >();
473+ List <AtomSite > list = new ArrayList <>();
471474
472475 if (c .getEntityInfo ()==null ) {
473476 logger .warn ("No Compound (entity) found for chain {}: entity_id will be set to 0, label_seq_id will be the same as auth_seq_id" , c .getName ());
@@ -477,7 +480,7 @@ public static List<AtomSite> convertChainToAtomSites(Chain c, int model, String
477480
478481 Group g = c .getAtomGroup (h );
479482
480- list .addAll (convertGroupToAtomSites (g , model , authorId , asymId ));
483+ list .addAll (convertGroupToAtomSites (g , model , chainName , chainId ));
481484
482485 }
483486
0 commit comments