code: public static void addCharges(Structure structure) {
  		// Loop through the models
  		for(int i=0; i<structure.nrModels(); i++){
  			for(Chain c: structure.getChains(i)){
  				for(Group g: c.getAtomGroups()){
  					ChemComp thisChemComp = ChemCompGroupFactory.getChemComp(g.getPDBName());
  					List<ChemCompAtom> chemAtoms = thisChemComp.getAtoms();
  					for(ChemCompAtom chemCompAtom : chemAtoms) {
  						Atom atom = g.getAtom(chemCompAtom.getAtom_id());
  						String stringCharge = chemCompAtom.getCharge();
  						short shortCharge = 0;
  						if (stringCharge!=null){
  							if(!stringCharge.equals("?")){
  								try{
  									shortCharge = Short.parseShort(stringCharge);
  								}
  								catch(NumberFormatException e){
  									logger.warn("Number format exception. Parsing '"+stringCharge+"' to short");
  								}
  							}
  							else{
  								logger.warn("? charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId());
  							}
  						}
  						else{
  							logger.warn("Null charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId());
  						}
  						if(atom!=null){
  							atom.setCharge(shortCharge);
  						}
  						// Now do the same for alt locs
  						for (Group altLoc : g.getAltLocs()) {
  							Atom altAtom = altLoc.getAtom(chemCompAtom.getAtom_id());
  							if(altAtom!=null){
  								altAtom.setCharge(shortCharge);
  							}
  						}
  					}
  				}
  
  			}
  		}
  	}
docs: Function to add the charges to a given structure.