1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
* Created on 26.04.2004
* @author Andreas Prlic
*
*/
package org.biojava.bio.structure;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.biojava.bio.structure.io.FileConvert;
/**
* Implementation of a PDB Structure. This class
* provides the data contained in a PDB file.
* to get structure objects from different sources
* see io package.
*
* @author Andreas Prlic
* @author Jules Jacobsen
* @since 1.4
* @version %I% %G%
*/
public class StructureImpl implements Structure, Serializable {
/**
*
*/
private static final long serialVersionUID = -8344837138032851347L;
String pdb_id ;
/* models is an ArrayList of ArrayLists */
List<List<Chain>> models;
//List<Chain> seqResList;
Map<String,Object> header ;
List<Map <String,Integer>> connections ;
List<Compound> compounds;
List<DBRef> dbrefs;
List<SSBond> ssbonds;
List<Site> sites;
List<Group> hetAtoms;
String name ;
private JournalArticle journalArticle;
private PDBHeader pdbHeader;
private PDBCrystallographicInfo crystallographicInfo;
boolean nmrflag ;
private Long id;
private boolean biologicalAssembly;
/**
* Constructs a StructureImpl object.
*/
public StructureImpl() {
super();
models = new ArrayList<List<Chain>>();
name = "";
nmrflag = false;
header = new HashMap<String,Object>();
connections = new ArrayList<Map<String,Integer>>();
compounds = new ArrayList<Compound>();
dbrefs = new ArrayList<DBRef>();
pdbHeader = new PDBHeader();
ssbonds = new ArrayList<SSBond>();
sites = new ArrayList<Site>();
hetAtoms = new ArrayList<Group>();
}
/** get the ID used by Hibernate
*
* @return the ID used by Hibernate
*/
public Long getId() {
return id;
}
/** set the ID used by Hibernate
*
* @param id
*/
public void setId(Long id) {
this.id = id;
}
/** construct a Structure object that only contains a single group
*
* @param g
*/
public StructureImpl(Group g){
this();
Chain c = new ChainImpl();
c.addGroup(g);
addChain(c);
}
/** construct a Structure object that contains a particular chain
*
* @param c
*/
public StructureImpl(Chain c){
this();
addChain(c);
}
/** returns an identical copy of this structure .
* @return an identical Structure object
*/
@SuppressWarnings("deprecation")
public Structure clone() {
Structure n = new StructureImpl();
// go through whole substructure and clone ...
// copy structure data
if (isNmr()) n.setNmr(true);
n.setPDBCode(getPDBCode());
n.setName(getName());
n.setHeader(getHeader());
//TODO: do deep copying of data!
n.setPDBHeader(pdbHeader);
n.setDBRefs(this.getDBRefs());
n.setConnections(getConnections());
n.setSites(getSites());
n.setCrystallographicInfo(getCrystallographicInfo());
// go through each chain and clone chain
for (int i=0;i<nrModels();i++){
List<Chain> cloned_model = new ArrayList<Chain>();
for (int j=0;j<size(i);j++){
Chain current_chain = (Chain) getChain(i,j);
Chain cloned_chain = (Chain) current_chain.clone();
cloned_model.add(cloned_chain);
}
n.addModel(cloned_model);
}
for (SSBond ssbond: ssbonds){
n.addSSBond(ssbond.clone());
}
//n.setSeqRes(this.getSeqRes());
return n ;
}
public Group findGroup(String chainId, String pdbResnum, int modelnr)
throws StructureException {
// if structure is xray there will be only one "model".
if ( modelnr > models.size())
throw new StructureException(" no model nr " + modelnr +
" in this structure. (contains "+models.size()+")");
Chain c = findChain(chainId,modelnr);
List<Group> groups = c.getAtomGroups();
// now iterate over all groups in this chain.
// in order to find the amino acid that has this pdbRenum.
Iterator<Group> giter = groups.iterator();
while (giter.hasNext()){
Group g = giter.next();
String rnum = g.getResidueNumber().toString();
//System.out.println(g + " >" + rnum + "< >" + pdbResnum + "<");
// we only mutate amino acids
// and ignore hetatoms and nucleotides in this case
if (rnum.equals(pdbResnum))
return g;
}
throw new StructureException("could not find group " + pdbResnum +
" in chain " + chainId);
}
public Group findGroup(String chainName, String pdbResnum) throws StructureException
{
return findGroup(chainName, pdbResnum, 0);
}
public Chain findChain(String chainId, int modelnr) throws StructureException {
List<Chain> chains = getChains(modelnr);
// iterate over all chains.
Iterator<Chain> iter = chains.iterator();
while (iter.hasNext()){
Chain c = iter.next();
if (c.getChainID().equals(chainId)) {
return c;
}
}
throw new StructureException("could not find chain \"" + chainId + "\" for PDB id " + pdb_id);
}
public Chain findChain(String chainId) throws StructureException {
return findChain(chainId,0);
}
/**
*
* set PDB code of structure .
* @see #getPDBCode
*
*/
public void setPDBCode (String pdb_id_) {
pdb_id = pdb_id_ ;
}
/**
*
* get PDB code of structure .
*
* @return a String representing the PDBCode value
* @see #setPDBCode
*/
public String getPDBCode () {
return pdb_id ;
}
/** set biological name of Structure.
*
* @see #getName
*
*/
public void setName(String nam) { name = nam; }
/** get biological name of Structure.
*
* @return a String representing the name
* @see #setName
*/
public String getName() { return name; }
/** set the Header data.
*
*
* @see #getHeader
*/
public void setHeader(Map<String,Object> h){ header = h; }
/** get Header data.
*
* @return a Map object representing the header of the Structure
*
* @see #setHeader
*/
public Map<String,Object> getHeader() { return header ;}
/** @see Structure interface.
*
*
*/
public void setConnections(List<Map<String,Integer>> conns) { connections = conns ; }
/**
* Returns the connections value.
*
* @return a List object representing the connections value
* @see Structure interface
* @see #setConnections
*/
public List<Map<String,Integer>> getConnections() { return connections ;}
/** add a new chain.
*
*/
public void addChain(Chain chain) {
int modelnr = 0 ;
addChain(chain,modelnr);
}
/** add a new chain, if several models are available.
*
*/
public void addChain(Chain chain, int modelnr) {
// if model has not been initialized, init it!
chain.setParent(this);
if ( models.size() == 0 ) {
List<Chain> model = new ArrayList<Chain>() ;
model.add(chain);
models.add(model);
} else {
List<Chain> model = models.get(modelnr);
model.add(chain);
}
}
/** retrieve a chain by it's position within the Structure.
*
* @param number an int
* @return a Chain object
*/
public Chain getChain(int number) {
int modelnr = 0 ;
return getChain(modelnr,number);
}
/** retrieve a chain by it's position within the Structure and model number.
*
* @param modelnr an int
* @param number an int
* @return a Chain object
*/
public Chain getChain(int modelnr,int number) {
List<Chain> model = models.get(modelnr);
Chain chain = model.get (number );
return chain ;
}
/** add a new model.
*
*/
public void addModel(List<Chain> model){
for (Chain c: model){
c.setParent(this);
}
models.add(model);
}
public void setChains(List<Chain> chains){
setModel(0,chains);
}
public void setModel(int position, List<Chain> model){
if (model == null)
throw new IllegalArgumentException("trying to set model to null!");
for (Chain c: model)
c.setParent(this);
//System.out.println("model size:" + models.size());
if (models.size() ==0){
models.add(model);
} else {
models.set(position, model);
}
}
/** string representation.
*
*/
public String toString(){
String newline = System.getProperty("line.separator");
StringBuffer str = new StringBuffer();
str.append("structure ");
str.append(name);
str.append(" ");
str.append(pdb_id);
str.append(" ");
if ( isNmr() ){
str.append( " models: ");
str.append(nrModels());
str.append(newline) ;
}
str.append(pdbHeader.toString());
str.append(newline) ;
for (int i=0;i<nrModels();i++){
if (isNmr() ) {
str.append(" model[");
str.append(i);
str.append("]:");
str.append(newline);
}
str.append(" chains:");
str.append(newline);
for (int j=0;j<size(i);j++){
Chain cha = (Chain)getChain(i,j);
List<Group> agr = cha.getAtomGroups("amino");
List<Group> hgr = cha.getAtomGroups("hetatm");
List<Group> ngr = cha.getAtomGroups("nucleotide");
str.append("chain " + j + ": >"+cha.getChainID()+"< ");
if ( cha.getHeader() != null){
Compound comp = cha.getHeader();
String molName = comp.getMolName();
if ( molName != null){
str.append(molName);
}
}
str.append(newline);
str.append(" length SEQRES: ").append(cha.getSeqResLength());
str.append(" length ATOM: ").append(cha.getAtomLength());
str.append(" aminos: ").append(agr.size());
str.append(" hetatms: ").append(hgr.size());
str.append(" nucleotides: "+ngr.size() + newline);
}
}
str.append("DBRefs: "+ dbrefs.size()+ newline);
for (DBRef dbref: dbrefs){
str.append(dbref.toPDB()).append(newline);
}
str.append("Molecules: ").append(newline);
Iterator<Compound> iter = compounds.iterator();
while (iter.hasNext()){
Compound mol = iter.next();
str.append(mol).append(newline);
}
return str.toString() ;
}
/** return number of chains , if NMR return number of chains of first model .
*
*/
public int size() {
int modelnr = 0 ;
if ( models.size() > 0) {
return models.get(modelnr).size();
}
else {
return 0 ;
}
}
/** return number of chains of model.
*
*/
public int size(int modelnr) { return getChains(modelnr).size(); }
// some NMR stuff :
/** return number of models. */
public int nrModels() {
return models.size() ;
}
/** is this structure an nmr structure ?
*/
public boolean isNmr() {return nmrflag ; }
/* set the nmr flag */
public void setNmr(boolean nmr) { nmrflag = nmr ; }
/** retrieve all chains of a model.
*
* @param modelnr an int
* @return a List object
*/
public List<Chain> getChains(int modelnr){
return getModel(modelnr);
}
public List<Chain> getChains(){
return getModel(0);
}
public void setChains(int modelnr, List<Chain> chains){
for (Chain c: chains){
c.setParent(this);
}
models.remove(modelnr);
models.add(modelnr, chains);
}
/** retrieve all Chains belonging to a model .
*
* @param modelnr an int
* @return a List object
*/
public List<Chain> getModel(int modelnr) {
List<Chain> model = models.get(modelnr);
return model;
}
public Chain getChainByPDB(String chainId, int modelnr)
throws StructureException{
List<Chain> chains = getChains(modelnr);
Iterator<Chain> iter = chains.iterator();
while ( iter.hasNext()){
Chain c = iter.next();
if ( c.getChainID().equals(chainId))
return c;
}
throw new StructureException("did not find chain with chainId \"" + chainId + "\"" + " for PDB id " + pdb_id);
}
public Chain getChainByPDB(String chainId)
throws StructureException{
return getChainByPDB(chainId,0);
}
/** create a String that contains the contents of a PDB file.
*
* @return a String that represents the structure as a PDB file.
*/
public String toPDB() {
FileConvert f = new FileConvert(this) ;
String str = f.toPDB();
return str ;
}
public boolean hasChain(String chainId) {
int modelnr = 0;
List<Chain> chains = getChains(modelnr);
Iterator<Chain> iter = chains.iterator();
while ( iter.hasNext()){
Chain c = iter.next();
// we check here with equals because we might want to distinguish between upper and lower case chains!
if ( c.getChainID().equals(chainId))
return true;
}
return false;
}
public void setCompounds(List<Compound>molList){
this.compounds = molList;
}
public List<Compound> getCompounds() {
return compounds;
}
public Compound getCompoundById(String molId) {
for (Compound mol : this.compounds){
if (mol.getMolId().equals(molId)){
return mol;
}
}
return null;
}
public List<DBRef> getDBRefs() {
return dbrefs;
}
public void setDBRefs(List<DBRef> dbrefs) {
if ( dbrefs == null)
throw new IllegalArgumentException("trying to set dbrefs to null!");
for( DBRef ref : dbrefs){
ref.setParent(this);
}
this.dbrefs = dbrefs;
}
public PDBHeader getPDBHeader() {
return pdbHeader;
}
public void setPDBHeader(PDBHeader pdbHeader){
this.pdbHeader = pdbHeader;
}
/** get the list of SSBonds as they have been defined in the PDB files
*
* @return a list of SSBonds
*/
public List<SSBond> getSSBonds(){
return ssbonds;
}
/** set the list of SSBonds for this structure
*
* @param ssbonds
*/
public void setSSBonds(List<SSBond> ssbonds){
this.ssbonds = ssbonds;
}
/** add a single SSBond to this structure
*
* @param ssbond the SSBond.
*/
public void addSSBond(SSBond ssbond){
ssbonds.add(ssbond);
ssbond.setSerNum(ssbonds.size());
}
/**
* 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.
*/
public boolean hasJournalArticle() {
if (this.journalArticle != null) {
return true;
}
return false;
}
/**
* get the associated publication as defined by the JRNL records in a PDB
* file.
* @return a JournalArticle
*/
public JournalArticle getJournalArticle() {
return this.journalArticle;
}
/**
* set the associated publication as defined by the JRNL records in a PDB
* file.
* @param journalArticle the article
*/
public void setJournalArticle(JournalArticle journalArticle) {
this.journalArticle = journalArticle;
}
/**
* @return the sites contained in this structure
*/
public List<Site> getSites() {
return sites;
}
/**
* @param sites the sites to set in the structure
*/
public void setSites(List<Site> 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.
*/
public List<Group> getHetGroups() {
return hetAtoms;
}
/**
* Sets a flag to indicate if this structure is a biological assembly
* @param biologicalAssembly true if biological assembly, otherwise false
* @since 3.2
*/
public void setBiologicalAssembly(boolean biologicalAssembly) {
this.biologicalAssembly = biologicalAssembly;
}
/**
* Gets flag that indicates if this structure is a biological assembly
* @return the sites contained in this structure
* @since 3.2
*/
public boolean isBiologicalAssembly() {
return biologicalAssembly;
}
/**
* Sets crystallographic information for this structure
* @param PDBCrystallographicInfo crystallographic information
* @since 3.2
*/
public void setCrystallographicInfo(PDBCrystallographicInfo crystallographicInfo) {
this.crystallographicInfo = crystallographicInfo;
}
/**
* Gets crystallographic information for this structure
* @return PDBCrystallographicInfo crystallographic information
* @since 3.2
*/
public PDBCrystallographicInfo getCrystallographicInfo() {
return crystallographicInfo;
}
@Override
public String getIdentifier() {
return pdb_id;
}
@Override
public String getPdbId() {
return pdb_id;
}
@Override
public List<ResidueRange> getResidueRanges() {
List<ResidueRange> range = new ArrayList<ResidueRange>();
for (Chain chain : getChains()) {
range.add(ResidueRange.parse(pdb_id + "." + chain.getChainID()));
}
return range;
}
@Override
public List<String> getRanges() {
return ResidueRange.toStrings(getResidueRanges());
}
}
|