diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Structure.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Structure.java index 51d69234c7..05bd0ba859 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Structure.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Structure.java @@ -178,10 +178,10 @@ public interface Structure extends Cloneable, Serializable { /** * Return number of chains of model. * - * @param modelnr an int specifying the number of the Model that should be used + * @param modelIdx an int specifying the index of the Model that should be used * @return an int representing the number of Chains in this Model */ - int size(int modelnr); + int size(int modelIdx); /** * Return the number of models . @@ -232,10 +232,10 @@ public interface Structure extends Cloneable, Serializable { * Retrieve all Chains belonging to a model . * @see #getChains(int modelnr) * - * @param modelnr an int + * @param modelIdx the model index * @return a List object containing the Chains of Model nr. modelnr */ - List getModel(int modelnr); + List getModel(int modelIdx); /** * Retrieve all chains for the first model. @@ -261,17 +261,17 @@ public interface Structure extends Cloneable, Serializable { * Retrieve all chains of a model. * @see #getModel * - * @param modelnr an int + * @param modelIdx the model index * @return a List object containing the Chains of Model nr. modelnr */ - List getChains(int modelnr); + List getChains(int modelIdx); /** * Set the chains for a model * @param chains the chains for a model - * @param modelnr the number of the model + * @param modelIdx the model index */ - void setChains( int modelnr, List chains); + void setChains(int modelIdx, List chains); /** * Return all polymeric chains for the first model @@ -315,7 +315,7 @@ public interface Structure extends Cloneable, Serializable { /** * Return all water chains for the given model index - * @param modelIdx + * @param modelIdx the model index * @return * @since 5.0 */ @@ -332,9 +332,9 @@ public interface Structure extends Cloneable, Serializable { * Add a new chain to the model specified by the given index * * @param chain a Chain object - * @param modelnr an int specifying to which model the Chain should be added + * @param modelIdx an int specifying to which model the Chain should be added */ - void addChain(Chain chain, int modelnr); + void addChain(Chain chain, int modelIdx); /** * Retrieve a chain by its index within the Structure . @@ -348,10 +348,10 @@ public interface Structure extends Cloneable, Serializable { * Retrieve a chain by its indices within the Structure and model. * * @param chainIndex the index of the desired chain in the structure - * @param modelnr the model the desired chain is in + * @param modelIdx the model index * @return a Chain object */ - Chain getChainByIndex(int modelnr, int chainIndex); + Chain getChainByIndex(int modelIdx, int chainIndex); /** * Check if a chain with the chainId aymId is contained in this structure. @@ -394,11 +394,11 @@ public interface Structure extends Cloneable, Serializable { * considers only model nr X. count starts with 0. * @param authId the chain name of the chain to use * @param pdbResnum the PDB residue number of the requested group - * @param modelnr the number of the model to use + * @param modelIdx the model index * @return Group the requested Group * @throws StructureException */ - Group findGroup(String authId, String pdbResnum, int modelnr) throws StructureException; + Group findGroup(String authId, String pdbResnum, int modelIdx) throws StructureException; /** * Retrieve a Chain (polymeric, non-polymeric or water) based on diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java index ae00c8f7f3..0a697e2d7b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java @@ -123,20 +123,15 @@ public Structure clone() { n.setDBRefs(this.getDBRefs()); n.setSites(getSites()); - // go through each chain and clone chain for (int i=0;i cloned_model = new ArrayList<>(); for (int j=0;j models.size()) - throw new StructureException(" no model nr " + modelnr + + if ( modelIdx > models.size()) + throw new StructureException(" no model nr " + modelIdx + " in this structure. (contains "+models.size()+")"); - // first we need to gather all groups with the author id chainName: polymers, non-polymers and waters - Chain polyChain = getPolyChainByPDB(chainName, modelnr); + Chain polyChain = getPolyChainByPDB(chainName, modelIdx); if(polyChain != null) { - List groups = new ArrayList<>(); - - groups.addAll(polyChain.getAtomGroups()); + List groups = new ArrayList<>(polyChain.getAtomGroups()); // there can be more than one non-poly chain for a given author id - for (Chain chain: getNonPolyChainsByPDB(chainName, modelnr)) { + for (Chain chain: getNonPolyChainsByPDB(chainName, modelIdx)) { groups.addAll(chain.getAtomGroups()); } - Chain water = getWaterChainByPDB(chainName, modelnr); + Chain water = getWaterChainByPDB(chainName, modelIdx); if (water!=null) groups.addAll(water.getAtomGroups()); - - // now iterate over all groups // in order to find the amino acid that has this pdbRenum. @@ -254,13 +243,12 @@ public void setStructureIdentifier(StructureIdentifier structureIdentifier) { /** {@inheritDoc} */ @Override public void addChain(Chain chain) { - int modelnr = 0 ; - addChain(chain,modelnr); + addChain(chain, 0); } /** {@inheritDoc} */ @Override - public void addChain(Chain chain, int modelnr) { + public void addChain(Chain chain, int modelIdx) { // if model has not been initialized, init it! chain.setStructure(this); if (models.isEmpty()) { @@ -271,37 +259,25 @@ public void addChain(Chain chain, int modelnr) { models.add(model); } else { - Model model = models.get(modelnr); + Model model = models.get(modelIdx); model.addChain(chain); } - - - } - - /** {@inheritDoc} */ @Override public Chain getChainByIndex(int number) { - - int modelnr = 0 ; - - return getChainByIndex(modelnr,number); + return getChainByIndex(0, number); } /** {@inheritDoc} */ @Override - public Chain getChainByIndex(int modelnr,int number) { - - Model model = models.get(modelnr); - + public Chain getChainByIndex(int modelIdx, int number) { + Model model = models.get(modelIdx); return model.getChains().get(number); } - - /** {@inheritDoc} */ @Override public void addModel(List modelChains){ @@ -313,16 +289,12 @@ public void addModel(List modelChains){ models.add(model); } - /** {@inheritDoc} */ @Override public void setChains(List chains){ - - setModel(0,chains); + setModel(0, chains); } - - /** {@inheritDoc} */ @Override public void setModel(int position, List modelChains){ @@ -333,8 +305,6 @@ public void setModel(int position, List modelChains){ c.setStructure(this); //System.out.println("model size:" + models.size()); - - Model model = new Model(); model.setChains(modelChains); @@ -345,12 +315,9 @@ public void setModel(int position, List modelChains){ } } - /** String representation. - * - */ @Override public String toString(){ - String newline = System.getProperty("line.separator"); + String newline = System.lineSeparator(); StringBuilder str = new StringBuilder(); str.append("structure "); str.append(name); @@ -384,17 +351,13 @@ public String toString(){ List hgr = cha.getAtomGroups(GroupType.HETATM); List ngr = cha.getAtomGroups(GroupType.NUCLEOTIDE); - - - str.append("chain ") .append(j).append(": asymId:") .append(cha.getId()) .append(" authId:") .append(cha.getName()).append(" "); - - if ( cha.getEntityInfo() != null){ + if (cha.getEntityInfo() != null){ EntityInfo comp = cha.getEntityInfo(); String molName = comp.getDescription(); if ( molName != null){ @@ -406,7 +369,6 @@ public String toString(){ .append(")"); } - str.append(newline); str.append(" length SEQRES: ").append(cha.getSeqResLength()); str.append(" length ATOM: ").append(cha.getAtomLength()); @@ -425,32 +387,21 @@ public String toString(){ str.append(mol).append(newline); } - return str.toString() ; } @Override public int size() { - int modelnr = 0 ; - if (!models.isEmpty()) { - return models.get(modelnr).getPolyChains().size(); - } - else { + return models.get(0).getPolyChains().size(); + } else { return 0 ; } - } - /** return number of chains of model. - * - */ @Override - public int size(int modelnr) { return models.get(modelnr).size(); } + public int size(int modelIdx) { return models.get(modelIdx).size(); } - // some NMR stuff : - - /** return number of models. */ @Override public int nrModels() { return models.size() ; @@ -520,16 +471,15 @@ public List getChains(int modelIdx){ /** {@inheritDoc} */ @Override public List getChains(){ - if (models.size()==0) { + if (models.isEmpty()) { return new ArrayList<>(0); } return getChains(0); - } @Override public List getPolyChains() { - if (models.size()==0) { + if (models.isEmpty()) { return new ArrayList<>(0); } return getPolyChains(0); @@ -542,7 +492,7 @@ public List getPolyChains(int modelIdx) { @Override public List getNonPolyChains() { - if (models.size()==0) { + if (models.isEmpty()) { return new ArrayList<>(0); } return getNonPolyChains(0); @@ -555,7 +505,7 @@ public List getNonPolyChains(int modelIdx) { @Override public List getWaterChains() { - if (models.size()==0) { + if (models.isEmpty()) { return new ArrayList<>(0); } return getWaterChains(0); @@ -566,55 +516,46 @@ public List getWaterChains(int modelIdx) { return models.get(modelIdx).getWaterChains(); } - - /** {@inheritDoc} */ @Override - public void setChains(int modelnr, List chains){ + public void setChains(int modelIdx, List chains){ for (Chain c: chains){ c.setStructure(this); } - if (models.size()>modelnr) { - models.remove(modelnr); + if (models.size()> modelIdx) { + models.remove(modelIdx); } Model model = new Model(); model.setChains(chains); - models.add(modelnr, model); - + models.add(modelIdx, model); } - /** Retrieve all Chains belonging to a model . - * - * @param modelnr an int - * @return a List object + /** + * {@inheritDoc} */ @Override - public List getModel(int modelnr) { - - return models.get(modelnr).getChains(); + public List getModel(int modelIdx) { + if (models.isEmpty()) return new ArrayList<>(); + return models.get(modelIdx).getChains(); } /** {@inheritDoc} */ @Override - public Chain getChain(String asymId, int modelnr) { - - List chains = getChains(modelnr); + public Chain getChain(String asymId, int modelIdx) { + List chains = getChains(modelIdx); for (Chain c : chains) { if (c.getId().equals(asymId)) { return c; } } return null; - } /** {@inheritDoc} */ @Override public Chain getChain(String asymId) { - return getChain(asymId,0); - } @Override @@ -625,6 +566,8 @@ public Chain getPolyChain(String asymId) { @Override public Chain getPolyChain(String asymId, int modelIdx) { + if (models.isEmpty()) return null; + Model model = models.get(modelIdx); if (model==null) { return null; @@ -637,7 +580,6 @@ public Chain getPolyChain(String asymId, int modelIdx) { return null; } - @Override public Chain getNonPolyChain(String asymId) { return getNonPolyChain(asymId, 0); @@ -655,7 +597,6 @@ public Chain getNonPolyChain(String asymId, int modelIdx) { if (c.getId().equals(asymId)) return c; } - return null; } @@ -693,7 +634,6 @@ public List getNonPolyChainsByPDB(String authId, int modelIdx) { return chains; } - List nonpolyChains = model.getNonPolyChains(); for (Chain c : nonpolyChains){ if (c.getName().equals(authId)) @@ -708,7 +648,6 @@ public Chain getWaterChain(String asymId) { return getWaterChain(asymId, 0); } - @Override public Chain getWaterChain(String asymId, int modelIdx) { Model model = models.get(modelIdx); @@ -729,7 +668,6 @@ public Chain getWaterChainByPDB(String authId) { return getWaterChainByPDB(authId, 0); } - @Override public Chain getWaterChainByPDB(String authId, int modelIdx) { Model model = models.get(modelIdx); @@ -745,8 +683,6 @@ public Chain getWaterChainByPDB(String authId, int modelIdx) { return null; } - - /** {@inheritDoc} */ @Override public String toPDB() { @@ -835,7 +771,6 @@ public EntityInfo getEntityById(int entityId) { return null; } - /** {@inheritDoc} */ @Override public List getDBRefs() { @@ -855,7 +790,6 @@ public void setDBRefs(List dbrefs) { this.dbrefs = dbrefs; } - /** {@inheritDoc} */ @Override public PDBHeader getPDBHeader() { @@ -872,7 +806,6 @@ public void setPDBHeader(PDBHeader pdbHeader){ @Override public List getSSBonds(){ return ssbonds; - } /** {@inheritDoc} */ @@ -882,9 +815,7 @@ public void setSSBonds(List ssbonds){ } /** - * Adds a single disulfide Bond to this structure - * - * @param ssbond the SSBond. + * {@inheritDoc} */ @Override public void addSSBond(Bond ssbond){ @@ -892,10 +823,7 @@ public void addSSBond(Bond ssbond){ } /** - * Return whether or not the entry has an associated journal article - * or publication. The JRNL section is not mandatory and thus may not be - * present. - * @return flag if a JournalArticle could be found. + * R{@inheritDoc} */ @Override public boolean hasJournalArticle() { @@ -903,9 +831,7 @@ public boolean hasJournalArticle() { } /** - * get the associated publication as defined by the JRNL records in a PDB - * file. - * @return a JournalArticle + * {@inheritDoc} */ @Override public JournalArticle getJournalArticle() { @@ -913,9 +839,7 @@ public JournalArticle getJournalArticle() { } /** - * set the associated publication as defined by the JRNL records in a PDB - * file. - * @param journalArticle the article + * {@inheritDoc} */ @Override public void setJournalArticle(JournalArticle journalArticle) { @@ -923,29 +847,21 @@ public void setJournalArticle(JournalArticle journalArticle) { } /** - * @return the sites contained in this structure + * {@inheritDoc} */ - @Override public List getSites() { return sites; } /** - * @param sites the sites to set in the structure + * {@inheritDoc} */ - @Override public void setSites(List sites) { this.sites = sites; } - /** Caution: we should probably remove this to avoid confusion. Currently this is always an empty list! - * - * @return a list of Groups listed in the HET records - this will not - * include any waters. - */ - /** * Sets a flag to indicate if this structure is a biological assembly * @param biologicalAssembly true if biological assembly, otherwise false @@ -1026,19 +942,17 @@ public void setPDBCode(String pdb_id){ pdbId = new PdbId(pdb_id); } } - - - /** {@inheritDoc} - * @since 6.0.0 - * */ + /** + * {@inheritDoc} + **/ public PdbId getPdbId() { return this.pdbId; } - /** {@inheritDoc} - * @since 6.0.0 - * */ + /** + * {@inheritDoc} + **/ public void setPdbId(PdbId pdbId) { this.pdbId = pdbId; }