public static ResidueNumber fromString ( String pdb_code ) { if ( pdb_code == null ) return null ; ResidueNumber residueNumber = new ResidueNumber ( ) ; Integer resNum = null ; String icode = null ; try { resNum = Integer . parseInt ( pdb_code ) ; } catch ( NumberFormatException e ) { // there is an insertion code.. // Split at any position that's either: // preceded by a digit and followed by a non-digit, or // preceded by a non-digit and followed by a digit. String [ ] spl = pdb_code . split ( "(?<=\\d)(?=\\D)|(?<=\\D)(?=\\d)" ) ; if ( spl . length == 2 ) { resNum = Integer . parseInt ( spl [ 0 ] ) ; icode = spl [ 1 ] ; } } residueNumber . setSeqNum ( resNum ) ; if ( icode == null ) residueNumber . setInsCode ( null ) ; else if ( icode . length ( ) > 0 ) residueNumber . setInsCode ( icode . charAt ( 0 ) ) ; return residueNumber ; }
Convert a string representation of a residue number to a residue number object . The string representation can be a integer followed by a character .