public static Monomer getMonomer ( String type , String id , String info ) throws MonomerException , NotationException , ChemistryException { try { if ( id . startsWith ( "[" ) && id . endsWith ( "]" ) ) { id = id . substring ( 1 , id . length ( ) - 1 ) ; } MonomerFactory monomerFactory = MonomerFactory . getInstance ( ) ; MonomerStore monomerStore = monomerFactory . getMonomerStore ( ) ; Monomer monomer ; /* Monomer was saved to the database */ monomer = monomerStore . getMonomer ( type , id ) ; if ( monomer == null ) { /* * smiles check! Maybe the smiles is already included in the data base */ if ( monomerFactory . getSmilesMonomerDB ( ) . get ( id ) != null ) { monomer = monomerFactory . getSmilesMonomerDB ( ) . get ( id ) ; return monomer ; } else { /* This has to be done */ monomer = monomerFactory . getSmilesMonomerDB ( ) . get ( id ) ; if ( monomer == null ) { /* Rgroups information are not given -> only smiles information */ AbstractChemistryManipulator manipulator = Chemistry . getInstance ( ) . getManipulator ( ) ; if ( manipulator . validateSMILES ( id ) ) { if ( type . equals ( Monomer . CHEMICAL_POLYMER_TYPE ) ) { monomer = generateTemporaryMonomer ( id , type , "X" ) ; } else if ( type . equals ( Monomer . PEPTIDE_POLYMER_TYPE ) ) { monomer = generateTemporaryMonomer ( id , type , "X" ) ; } else if ( type . equals ( Monomer . NUCLIEC_ACID_POLYMER_TYPE ) ) { monomer = generateTemporaryMonomer ( id , type , info ) ; } } else { if ( ! id . equals ( "?" ) && ! id . equals ( "X" ) && ! id . equals ( "N" ) ) { throw new MonomerException ( "Defined Monomer is not in the database and also not valid SMILES " + id ) ; } else { return new Monomer ( type , "Undefined" , id , id ) ; } } /* Add new monomer to the database */ MonomerFactory . getInstance ( ) . getMonomerStore ( ) . addNewMonomer ( monomer ) ; MonomerFactory . getInstance ( ) . getSmilesMonomerDB ( ) . put ( monomer . getCanSMILES ( ) , monomer ) ; // save monomer db to local file after successful update // MonomerFactory . getInstance ( ) . saveMonomerCache ( ) ; LOG . info ( "Monomer was added to the database" ) ; } } } try { List < Attachment > idList = monomer . getAttachmentList ( ) ; for ( Attachment att : idList ) { if ( att . getCapGroupSMILES ( ) == null ) { MonomerParser . fillAttachmentInfo ( att ) ; } } } catch ( CTKException | JDOMException ex ) { throw new MonomerException ( "Attachments could not be filled with default attachments" ) ; } return monomer ; } catch ( IOException e ) { e . printStackTrace ( ) ; /* * monomer is not in the database and also not a valid SMILES -> throw * exception */ throw new MonomerException ( "Defined Monomer is not in the database and also not a valid SMILES " + id ) ; } }
method to get the monomer from the database!