4949import java .io .*;
5050import java .nio .charset .StandardCharsets ;
5151import java .util .TreeMap ;
52+ import java .util .regex .Matcher ;
53+ import java .util .regex .Pattern ;
5254
5355public class MolfileParser
5456{
@@ -647,9 +649,9 @@ private void interpretV3AtomLine(String line) throws IOException
647649 if (l != 0 ) {
648650 v = interpretV3AtomList (line );
649651 if (l < 0 )
650- bNotList = true ;
652+ bNotList = true ;
651653 index2 = Math .abs (l );
652- }
654+ }
653655 index1 = indexOfNextItem (line ,index2 );
654656 index2 = endOfItem (line ,index1 );
655657 float x = Float .parseFloat (line .substring (index1 ,index2 ));
@@ -694,10 +696,11 @@ private void interpretV3AtomLine(String line) throws IOException
694696 String specifier = line .substring (index1 ,index2 );
695697 int index = specifier .indexOf ('=' );
696698 String field = specifier .substring (0 ,index );
697- int value = Integer .parseInt (specifier .substring (index + 1 ));
698699 if (field .equals ("CHG" )){
700+ int value = Integer .parseInt (specifier .substring (index + 1 ));
699701 mMol .setAtomCharge (atom ,value );
700702 } else if (field .equals ("RAD" )){
703+ int value = Integer .parseInt (specifier .substring (index + 1 ));
701704 switch (value ){
702705 case 1 :
703706 mMol .setAtomRadical (atom ,Molecule .cAtomRadicalStateS );
@@ -713,10 +716,13 @@ private void interpretV3AtomLine(String line) throws IOException
713716 // don't read parities from molfile, they are calculated from up/down bonds
714717 // mMol.setAtomParity(atom, value, false);
715718 } else if (field .equals ("MASS" )){
719+ int value = Integer .parseInt (specifier .substring (index + 1 ));
716720 mMol .setAtomMass (atom ,value );
717721 } else if (field .equals ("VAL" )){
722+ int value = Integer .parseInt (specifier .substring (index + 1 ));
718723 mMol .setAtomAbnormalValence (atom , (value ==-1 ) ? 0 : (value ==0 ) ? -1 : value );
719724 } else if (field .equals ("HCOUNT" )){
725+ int value = Integer .parseInt (specifier .substring (index + 1 ));
720726 switch (value ){
721727 case 0 :
722728 break ;
@@ -739,6 +745,7 @@ private void interpretV3AtomLine(String line) throws IOException
739745 break ;
740746 }
741747 } else if (field .equals ("SUBST" )){
748+ int value = Integer .parseInt (specifier .substring (index + 1 ));
742749 if (value == -1 ){
743750 mMol .setAtomQueryFeature (atom ,Molecule .cAtomQFNoMoreNeighbours ,true );
744751 } else if (value > 0 ){
@@ -754,6 +761,7 @@ private void interpretV3AtomLine(String line) throws IOException
754761 }
755762 }
756763 } else if (field .equals ("RBCNT" )){
764+ int value = Integer .parseInt (specifier .substring (index + 1 ));
757765 switch (value ){
758766 case -1 :
759767 mMol .setAtomQueryFeature (atom ,
@@ -789,6 +797,13 @@ private void interpretV3AtomLine(String line) throws IOException
789797 true );
790798 break ;
791799 }
800+ } else if (field .equals ("RGROUPS" )) {
801+ Pattern pattern = Pattern .compile ("RGROUPS=\\ ((\\ d+) (\\ d+).*\\ )" );
802+ Matcher matcher = pattern .matcher (line );
803+ if (matcher .find ()) {
804+ String rgLabel = "R" +matcher .group (2 );
805+ mMol .setAtomCustomLabel (atom ,rgLabel );
806+ }
792807 } else {
793808 TRACE ("Warning MolfileParser: Unused version 3 atom specifier:" + field + "\n " );
794809 }
@@ -1000,12 +1015,12 @@ private int[] interpretV3AtomList(String line)
10001015 /**
10011016 * Checks whether or not the atom description contains an atom list
10021017 * @param line String Atom description line
1003- * @return int negative if an exclusion (NOT) list is present, positive if an atom list is present, 0 if no atom list.
1018+ * @return int negative if an exclusion (NOT) list is present, positive if an atom list is present, 0 if no atom list.
10041019 * The values for negative and positive results represent the index to the closing ']' bracket
10051020 */
10061021 private int isV3AtomList (String line )
10071022 {
1008-
1023+
10091024 // simple check for atom list
10101025 if (line .indexOf ("[" ) >= 0 ) {
10111026 // Detail check for non-quoted version
@@ -1019,7 +1034,7 @@ private int isV3AtomList(String line)
10191034 if (i1 >= 0 && i2 > 0 ){
10201035 return i2 +1 ; // point after the ]'
10211036 }
1022- }
1037+ }
10231038
10241039 // Detail check for quoted version
10251040 i1 = line .indexOf (" 'NOT[" );
@@ -1032,7 +1047,7 @@ private int isV3AtomList(String line)
10321047 if (i1 >= 0 && i2 > 0 ){
10331048 return i2 +2 ; // point after the ]'
10341049 }
1035- }
1050+ }
10361051 System .err .println ("Warning invalid atom list in line: " + line );
10371052 }
10381053 return 0 ;
0 commit comments