コード例 #1
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addAtom(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     List<Atom> atoms = actualSection.getAtoms();
     AtomImpl a = new AtomImpl();
     int length = split.size();
     if (length >= 7) {
       a.setNr(Integer.parseInt(split.get(0)));
       a.setType(split.get(1));
       a.setResNr(Integer.parseInt(split.get(2)));
       a.setResName(split.get(3));
       a.setAtomName(split.get(4));
       a.setChargeGroupNr(Integer.parseInt(split.get(5)));
       a.setC1(new BigDecimal(split.get(6)));
     }
     if (length >= 8) {
       a.setC2(new BigDecimal(split.get(7)));
     }
     if (length == 11) {
       a.setTypeB(split.get(8));
       a.setC3(new BigDecimal(split.get(9)));
       a.setC4(new BigDecimal(split.get(10)));
     }
     if (length < 7 || length > 11) {
       ch.printErrorln(String.format("some ATOMS values are lost! --> %s", line));
     } else {
       atoms.add(a);
     }
   }
 }
コード例 #2
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addAngle(String line, Section actualSection) {
   if (actualSection != null) {
     List<Angle> angles = actualSection.getAngles();
     List<String> split = reworkLine(line);
     int length = split.size();
     AngleImpl a = new AngleImpl();
     if (length >= 4) {
       a.setAi(split.get(0));
       a.setAj(split.get(1));
       a.setAk(split.get(2));
       a.setFuncType(Integer.parseInt(split.get(3)));
     }
     if (length >= 6) {
       a.setC1(new BigDecimal(split.get(4)));
       a.setC2(new BigDecimal(split.get(5)));
     }
     if (length >= 7) {
       a.setC3(new BigDecimal(split.get(6)));
     }
     if (length >= 8) {
       a.setC4(new BigDecimal(split.get(7)));
     }
     if (length >= 10) {
       a.setC5(new BigDecimal(split.get(8)));
       a.setC6(new BigDecimal(split.get(9)));
     }
     if (length < 4 || length > 10) {
       ch.printErrorln(String.format("some ANGLES values are lost! --> %s", line));
     } else {
       angles.add(a);
     }
   }
 }
コード例 #3
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addBond(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     List<Bond> bonds = actualSection.getBonds();
     int length = split.size();
     BondImpl b = new BondImpl();
     if (length >= 3) {
       b.setAi(split.get(0));
       b.setAj(split.get(1));
       b.setFuncType(Integer.parseInt(split.get(2)));
     }
     if (length >= 5) {
       b.setC1(new BigDecimal(split.get(3)));
       b.setC2(new BigDecimal(split.get(4)));
     }
     if (length >= 6) {
       b.setC3(new BigDecimal(split.get(5)));
     }
     if (length >= 7) {
       b.setC4(new BigDecimal(split.get(6)));
     }
     if (length < 3 || length > 7) {
       ch.printErrorln(String.format("some BONDS values are lost! --> %s", line));
     } else {
       bonds.add(b);
     }
   }
 }
コード例 #4
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addPair(String line, Section actualSection) {
   if (actualSection != null) {
     List<Pair> pairs = actualSection.getPairs();
     List<String> split = reworkLine(line);
     PairImpl p = new PairImpl();
     int length = split.size();
     if (length >= 3) {
       p.setAi(split.get(0));
       p.setAj(split.get(1));
       p.setFuncType(Integer.parseInt(split.get(2)));
     }
     if (length >= 5) {
       p.setC1(new BigDecimal(split.get(3)));
       p.setC2(new BigDecimal(split.get(4)));
     }
     if (length >= 7) {
       p.setC3(new BigDecimal(split.get(5)));
       p.setC4(new BigDecimal(split.get(6)));
     }
     if (length == 8) {
       p.setC5(new BigDecimal(split.get(7)));
     }
     if (length < 3 || length > 8) {
       ch.printErrorln(String.format("some PAIRS values are lost! --> %s", line));
     } else {
       pairs.add(p);
     }
   }
 }
コード例 #5
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addDihedralRes(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     List<DihedralRestraint> diheRes = actualSection.getDihedralRestraints();
     DihedralRestraintImpl res = new DihedralRestraintImpl();
     if (split.size() == 7) {
       res.setAi(split.get(0));
       res.setAj(split.get(1));
       res.setAk(split.get(2));
       res.setAl(split.get(3));
       res.setFuncType(Integer.parseInt(split.get(4)));
       res.setC1(new BigDecimal(split.get(5)));
       res.setC2(new BigDecimal(split.get(6)));
       diheRes.add(res);
     } else if (split.size() == 10) {
       res.setAi(split.get(0));
       res.setAj(split.get(1));
       res.setAk(split.get(2));
       res.setAl(split.get(3));
       res.setFuncType(Integer.parseInt(split.get(4)));
       res.setLabel(split.get(5));
       res.setC1(new BigDecimal(split.get(6)));
       res.setC2(new BigDecimal(split.get(7)));
       res.setC3(new BigDecimal(split.get(8)));
       res.setC4(new BigDecimal(split.get(9)));
       diheRes.add(res);
     } else {
       ch.printErrorln(String.format("some dihedral restraints values are lost! --> %s", line));
     }
   }
 }
コード例 #6
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addAngleRes(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     List<AngleRestraintZImpl> angleRes = actualSection.getAngleRestraints();
     if (split.size() == 6) {
       AngleRestraintZImpl resZ = new AngleRestraintZImpl();
       resZ.setAi(split.get(0));
       resZ.setAj(split.get(1));
       resZ.setFuncType(Integer.parseInt(split.get(2)));
       resZ.setC1(new BigDecimal(split.get(3)));
       resZ.setC2(new BigDecimal(split.get(4)));
       resZ.setC3(new BigDecimal(split.get(5)));
       angleRes.add(resZ);
     } else if (split.size() == 8) {
       AngleRestraintImpl res = new AngleRestraintImpl();
       res.setAi(split.get(0));
       res.setAj(split.get(1));
       res.setAk(split.get(2));
       res.setAl(split.get(3));
       res.setFuncType(Integer.parseInt(split.get(4)));
       res.setC1(new BigDecimal(split.get(5)));
       res.setC2(new BigDecimal(split.get(6)));
       res.setC3(new BigDecimal(split.get(7)));
       angleRes.add(res);
     } else {
       ch.printErrorln(String.format("some angles restraints(z) values are lost! --> %s", line));
     }
   }
 }
コード例 #7
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
  private void removeUnnecessaryData() {
    Set<AtomType> clear = Sets.newHashSet();
    List<Atom> atoms = Lists.newArrayList();
    List<AtomType> atomTypes = structure.getAtomTypes();

    for (Section section : structure.getSections()) {
      if (section.getSectionType().equals(SectionType.STRUCTUREDATA)) {
        atoms.addAll(section.getAtoms());
      }
    }
    for (AtomType atomType : atomTypes) {
      AtomType delete = atomType;
      for (Atom atom : atoms) {
        if (atomType.getName().contains(atom.getType())) {
          delete = null;
        }
      }
      if (delete != null) {
        clear.add(delete);
      }
    }
    clear.forEach(atomTypes::remove);
  }
コード例 #8
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addSettle(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     if (split.size() == 4) {
       List<Settle> settles = actualSection.getSettles();
       SettleImpl s = new SettleImpl();
       s.setAtom(split.get(0));
       s.setFuncType(Integer.parseInt(split.get(1)));
       s.setC1(new BigDecimal(split.get(2)));
       s.setC2(new BigDecimal(split.get(3)));
       settles.add(s);
     } else {
       ch.printErrorln(String.format("some SETTLES values are lost! --> %s", line));
     }
   }
 }
コード例 #9
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addPosres(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     if (split.size() == 5) {
       List<PositionRestraint> posres = actualSection.getPositionRestraints();
       PositionRestraintImpl pr = new PositionRestraintImpl();
       pr.setAi(split.get(0));
       pr.setFuncType(Integer.parseInt(split.get(1)));
       pr.setC1(new BigDecimal(split.get(2)));
       pr.setC2(new BigDecimal(split.get(3)));
       pr.setC3(new BigDecimal(split.get(4)));
       posres.add(pr);
     } else {
       ch.printErrorln(String.format("some POSRES values are lost! --> %s", line));
     }
   }
 }
コード例 #10
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addExclusion(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     if (split.size() >= 2) {
       List<Exclusion> exclusions = actualSection.getExclusions();
       Exclusion e = new Exclusion();
       e.setAtomIdx(Integer.parseInt(split.get(0)));
       List<Integer> bonds = e.getBonds();
       for (int i = 1; i < split.size(); i++) {
         bonds.add(Integer.parseInt(split.get(i)));
       }
       exclusions.add(e);
     } else {
       ch.printErrorln(String.format("some EXCLUSIONS values are lost! --> %s", line));
     }
   }
 }
コード例 #11
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addPairNB(String line, Section actualSection) {
   if (actualSection != null) {
     List<PairNB> pairsNB = actualSection.getPairsNB();
     List<String> split = reworkLine(line);
     if (split.size() == 7) {
       PairNB p = new PairNB();
       p.setAi(split.get(0));
       p.setAj(split.get(1));
       p.setFuncType(Integer.parseInt(split.get(2)));
       p.setC1(new BigDecimal(split.get(3)));
       p.setC2(new BigDecimal(split.get(4)));
       p.setC3(new BigDecimal(split.get(5)));
       p.setC4(new BigDecimal(split.get(6)));
       pairsNB.add(p);
     } else {
       ch.printErrorln(String.format("some PAIRS values are lost! --> %s", line));
     }
   }
 }
コード例 #12
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addOrientationRes(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     if (split.size() == 9) {
       List<OrientationRestraint> oriRes = actualSection.getOrientationRestraints();
       OrientationRestraintImpl res = new OrientationRestraintImpl();
       res.setAi(split.get(0));
       res.setAj(split.get(1));
       res.setFuncType(Integer.parseInt(split.get(2)));
       res.setExp(split.get(3));
       res.setLabel(split.get(3));
       res.setAlpha(split.get(3));
       res.setC1(new BigDecimal(split.get(3)));
       res.setC2(new BigDecimal(split.get(3)));
       res.setC3(new BigDecimal(split.get(3)));
       oriRes.add(res);
     } else {
       ch.printErrorln(String.format("some orientation restraints values are lost! --> %s", line));
     }
   }
 }
コード例 #13
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addConstraint(String line, Section actualSection) {
   if (actualSection != null) {
     List<String> split = reworkLine(line);
     List<Constraint> constraints = actualSection.getConstraints();
     ConstraintImpl c = new ConstraintImpl();
     int length = split.size();
     if (length >= 4) {
       c.setAi(split.get(0));
       c.setAj(split.get(1));
       c.setFuncType(Integer.parseInt(split.get(2)));
       c.setC1(new BigDecimal(split.get(3)));
     }
     if (length == 5) {
       c.setC2(new BigDecimal(split.get(4)));
     }
     if (length < 4 || length > 5) {
       ch.printErrorln(String.format("some CONSTRAINTS values are lost! --> %s", line));
     } else {
       constraints.add(c);
     }
   }
 }
コード例 #14
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addDihedral(String line, Section actualSection) {
   if (actualSection != null) {
     List<Dihedral> dihedrals = actualSection.getDihedrals();
     List<String> split = reworkLine(line);
     DihedralImpl dh = new DihedralImpl();
     int length = split.size();
     if (length >= 5) {
       dh.setAi(split.get(0));
       dh.setAj(split.get(1));
       dh.setAk(split.get(2));
       dh.setAl(split.get(3));
       dh.setFuncType(Integer.parseInt(split.get(4)));
     }
     if (length >= 7) {
       dh.setC1(new BigDecimal(split.get(5)));
       dh.setC2(new BigDecimal(split.get(6)));
     }
     if (length >= 8) {
       dh.setC3(new BigDecimal(split.get(7)));
     }
     if (length >= 9) {
       dh.setC4(new BigDecimal(split.get(8)));
     }
     if (length >= 10) {
       dh.setC5(new BigDecimal(split.get(9)));
     }
     if (length == 11) {
       dh.setC6(new BigDecimal(split.get(10)));
     }
     if (length < 5 || length > 11) {
       ch.printErrorln(String.format("some DIHEDRALS values are lost! --> %s", line));
     } else {
       dihedrals.add(dh);
     }
   }
 }
コード例 #15
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
  // Recursive function able to run posres and ff files too
  public void parseInput(
      byte[] input, Path posres, boolean header, String previousPath, Map<String, String> arguments)
      throws IOException, URISyntaxException, NumberFormatException {
    // TODO: exclude unnecessary data from ff include
    if (input == null) return;
    if (arguments != null) {
      args = arguments;
    }
    boolean defaults = false;
    boolean pairs = false;
    boolean pairNB = false;
    boolean pairTypes = false;
    boolean atoms = false;
    boolean atomTypes = false;
    boolean bonds = false;
    boolean bondTypes = false;
    boolean constraints = false;
    boolean constraintTypes = false;
    boolean angles = false;
    boolean angleTypes = false;
    boolean dihedrals = false;
    boolean dihedralTypes = false;
    boolean molecules = false;
    boolean moleculeTypes = false;
    boolean genbornParams = false;
    boolean settles = false;
    boolean system = false;
    boolean exclusions = false;
    boolean positionrestraints = false;
    boolean distanceRes = false;
    boolean nonbondParams = false;
    boolean dihedralsRes = false;
    boolean orientationRes = false;
    boolean angleRes = false;
    boolean skipIfPath = false;
    boolean skipElsePath = true;
    boolean elseReached = false;

    Section actualSection = null;
    String line;
    InputStream stream = new ByteArrayInputStream(input);
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    while ((line = reader.readLine()) != null) {
      line = line.trim();
      line = replaceDefineCalls(line);
      if (LOGICAL_PATTERN.matcher(line).matches()) {
        if (line.contains("HEAVY_H")) {
          if (line.contains(ifdef)) {
            if (args.get("heavyW").equals("false")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          } else if (line.contains(ifndef)) {
            if (args.get("heavyW").equals("true")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          }
        } else if (line.contains("FLEXIBLE")) {
          if (line.contains(ifdef)) {
            if (args.get("flex").equals("false")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          } else if (line.contains(ifndef)) {
            if (args.get("flex").equals("true")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          }
        } else if (line.contains("POSRES_WATER")) {
          if (line.contains(ifdef)) {
            if (args.get("posreswat").equals("false")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          } else if (line.contains(ifndef)) {
            if (args.get("posreswat").equals("true")) {
              skipIfPath = true;
              skipElsePath = false;
            }
          }
        } else if (line.contains(define)) {
          // List<String> strings = reworkLineRemovePrefix(line, define);
          // defines.put(strings.get(0), Joiner.on(" ").join(strings.subList(1, strings.size())));
        } else if (line.contains(elsse)) {
          elseReached = true;
          if (skipIfPath) skipElsePath = false;
          skipIfPath = false;
        } else if (line.contains(endif)) {
          skipIfPath = false;
          skipElsePath = true;
          elseReached = false;
        }
        if (INCLUDE_PATTERN.matcher(line).matches()) {
          String file = line.split(" ")[1];
          file = file.substring(1, file.length() - 1);
          if (posres != null && posres.endsWith(file)) {
            parseInput(
                Files.readAllBytes(posres),
                null,
                false,
                previousPath != null ? previousPath : file.split("/")[0],
                null);
            continue;
          }
          if (previousPath != null) {
            file = previousPath + "/" + file;
          }
          if (posres == null || args.get("posres").equals("false")) {
            continue;
          }
          byte[] byName = IncludeHandler.getFileByName(GromacsTReader.class, file);
          if (byName == null) {
            throw new RuntimeException(String.format("File: %s could not be found!", file));
          }
          parseInput(
              byName, null, false, previousPath != null ? previousPath : file.split("/")[0], null);
        }
        continue;
      }
      if (skipIfPath || (skipElsePath && elseReached)) {
        continue;
      }
      if (COMMENT_PATTERN.matcher(line).matches() && header) {
        if (line.length() > 0) {
          addHeader(line);
        }
      } else {
        header = false;
      }
      if (DEFAULTS_PATTERN_1.matcher(line).matches() || defaults) {
        defaults = true;
        if (DEFAULTS_PATTERN_2.matcher(line).matches()) {
          addDefault(line);
        } else if (isDataRow(line) && !DEFAULTS_PATTERN_1.matcher(line).matches()) {
          defaults = false;
        }
      }
      if (PAIRS_PATTERN_1.matcher(line).matches() || pairs) {
        pairs = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for pairs found.");
          }
        }
        if (PAIRS_PATTERN_2.matcher(line).matches()) {
          addPair(line, actualSection);
        } else if (isDataRow(line) && !PAIRS_PATTERN_1.matcher(line).matches()) {
          pairs = false;
        }
      }
      if (PAIRSNB_PATTERN_1.matcher(line).matches() || pairNB) {
        pairNB = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for nonbonded pairs found.");
          }
        }
        if (PAIRS_PATTERN_2.matcher(line).matches()) {
          addPairNB(line, actualSection);
        } else if (isDataRow(line) && !PAIRSNB_PATTERN_1.matcher(line).matches()) {
          pairNB = false;
        }
      }
      if (PAIRTYPES_PATTERN_1.matcher(line).matches() || pairTypes) {
        pairTypes = true;
        if (PAIRS_PATTERN_2.matcher(line).matches()) {
          addPairType(line);
        } else if (isDataRow(line) && !PAIRTYPES_PATTERN_1.matcher(line).matches()) {
          pairTypes = false;
        }
      }
      if (ATOMS_PATTERN_1.matcher(line).matches() || atoms) {
        atoms = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for atoms found.");
          }
        }
        if (ATOMS_PATTERN_2.matcher(line).matches()) {
          addAtom(line, actualSection);
        } else if (isDataRow(line) && !ATOMS_PATTERN_1.matcher(line).matches()) {
          atoms = false;
        }
      }
      if (ATOMTYPES_PATTERN_1.matcher(line).matches() || atomTypes) {
        atomTypes = true;
        if (ATOMTYPES_PATTERN_2.matcher(line).matches()) {
          addAtomType(line);
        } else if (isDataRow(line) && !ATOMTYPES_PATTERN_1.matcher(line).matches()) {
          atomTypes = false;
        }
      }
      if (BONDS_PATTERN_1.matcher(line).matches() || bonds) {
        bonds = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for bonds found.");
          }
        }
        if (BONDS_PATTERN_2.matcher(line).matches()) {
          addBond(line, actualSection);
        } else if (isDataRow(line) && !BONDS_PATTERN_1.matcher(line).matches()) {
          bonds = false;
        }
      }
      if (BONDTYPES_PATTERN_1.matcher(line).matches() || bondTypes) {
        bondTypes = true;
        if (BONDS_PATTERN_2.matcher(line).matches()) {
          addBondType(line);
        } else if (isDataRow(line) && !BONDTYPES_PATTERN_1.matcher(line).matches()) {
          bondTypes = false;
        }
      }
      if (CONSTRAINTS_PATTERN_1.matcher(line).matches() || constraints) {
        constraints = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for constraints found.");
          }
        }
        if (CONSTRAINTS_PATTERN_2.matcher(line).matches()) {
          addConstraint(line, actualSection);
        } else if (isDataRow(line) && !CONSTRAINTTYPES_PATTERN_1.matcher(line).matches()) {
          constraints = false;
        }
      }
      if (CONSTRAINTTYPES_PATTERN_1.matcher(line).matches() || constraintTypes) {
        constraintTypes = true;
        if (CONSTRAINTS_PATTERN_2.matcher(line).matches()) {
          addConstraintType(line);
        } else if (isDataRow(line) && !CONSTRAINTTYPES_PATTERN_1.matcher(line).matches()) {
          constraintTypes = false;
        }
      }
      if (ANGLES_PATTERN_1.matcher(line).matches() || angles) {
        angles = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for angles found.");
          }
        }
        if (ANGLES_PATTERN_2.matcher(line).matches()) {
          addAngle(line, actualSection);
        } else if (isDataRow(line) && !ANGLES_PATTERN_1.matcher(line).matches()) {
          angles = false;
        }
      }
      if (ANGLETYPES_PATTERN_1.matcher(line).matches() || angleTypes) {
        angleTypes = true;
        if (ANGLES_PATTERN_2.matcher(line).matches()) {
          addAngleType(line);
        } else if (isDataRow(line) && !ANGLETYPES_PATTERN_1.matcher(line).matches()) {
          angleTypes = false;
        }
      }
      if (DIHEDRALS_PATTERN_1.matcher(line).matches() || dihedrals) {
        dihedrals = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for dihedrals found.");
          }
        }
        if (DIHEDRALS_PATTERN_2.matcher(line).matches()) {
          addDihedral(line, actualSection);
        } else if (isDataRow(line) && !DIHEDRALS_PATTERN_1.matcher(line).matches()) {
          dihedrals = false;
        }
      }
      if (DIHEDRALTYPES_PATTERN_1.matcher(line).matches() || dihedralTypes) {
        dihedralTypes = true;
        if (DIHEDRALS_PATTERN_2.matcher(line).matches()) {
          addDihedralType(line);
        } else if (isDataRow(line) && !DIHEDRALTYPES_PATTERN_1.matcher(line).matches()) {
          dihedralTypes = false;
        }
      }
      if (MOLECULES_PATTERN_1.matcher(line).matches() || molecules) {
        molecules = true;
        if (MOLECULES_PATTERN_2.matcher(line).matches() && structure.getMolecule() == null) {
          List<String> split = reworkLine(line);
          structure.setMolecule(new MoleculeImpl(split.get(0), Integer.parseInt(split.get(1))));
        } else if (isDataRow(line) && !MOLECULES_PATTERN_1.matcher(line).matches()) {
          molecules = false;
        }
      }
      if (MOLECULETYPES_PATTERN_1.matcher(line).matches() || moleculeTypes) {
        if (!moleculeTypes) {
          actualSection = null;
        }
        moleculeTypes = true;
        if (MOLECULES_PATTERN_2.matcher(line).matches() && actualSection == null) {
          List<String> split = reworkLine(line);
          Molecule moleculeType = new MoleculeImpl(split.get(0), Integer.parseInt(split.get(1)));
          if (previousPath == null) {
            actualSection = new Section(SectionType.STRUCTUREDATA);
          } else {
            actualSection = new Section(SectionType.FORCEFIELD);
          }
          actualSection.setMoleculeType(moleculeType);
          structure.getSections().add(actualSection);
        } else if (isDataRow(line) && !MOLECULETYPES_PATTERN_1.matcher(line).matches()) {
          moleculeTypes = false;
        }
      }
      if (IMPLICIT_GENBORN_PARAMS_PATTERN_1.matcher(line).matches() || genbornParams) {
        genbornParams = true;
        if (IMPLICIT_GENBORN_PARAMS_PATTERN_2.matcher(line).matches()) {
          addGenbornParam(line);
        } else if (isDataRow(line) && !IMPLICIT_GENBORN_PARAMS_PATTERN_1.matcher(line).matches()) {
          genbornParams = false;
        }
      }
      if (SETTLES_PATTERN_1.matcher(line).matches() || settles) {
        settles = true;
        if (SETTLES_PATTERN_2.matcher(line).matches()) {
          addSettle(line, actualSection);
        } else if (isDataRow(line) && !SETTLES_PATTERN_1.matcher(line).matches()) {
          settles = false;
        }
      }
      if (SYSTEM_PATTERN_1.matcher(line).matches() || system) {
        system = true;
        if (SYSTEM_PATTERN_2.matcher(line).matches() && structure.getSystem() == null) {
          structure.setSystem(new System(line));
        } else if (isDataRow(line) && !SYSTEM_PATTERN_1.matcher(line).matches()) {
          system = false;
        }
      }
      if (EXCLUSIONS_PATTERN_1.matcher(line).matches() || exclusions) {
        exclusions = true;
        if (actualSection == null && EXCLUSIONS_PATTERN_2.matcher(line).matches()) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.FORCEFIELD);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for exclusions found.");
          }
        }
        if (EXCLUSIONS_PATTERN_2.matcher(line).matches()) {
          addExclusion(line, actualSection);
        } else if (isDataRow(line) && !EXCLUSIONS_PATTERN_1.matcher(line).matches()) {
          exclusions = false;
        }
      }
      if (POSRES_PATTERN_1.matcher(line).matches() || positionrestraints) {
        positionrestraints = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for position restraints found.");
          }
        }
        if (POSRES_PATTERN_2.matcher(line).matches()) {
          addPosres(line, actualSection);
        } else if (isDataRow(line) && !POSRES_PATTERN_1.matcher(line).matches()) {
          positionrestraints = false;
        }
      }
      if (DISTANCERES_PATTERN_1.matcher(line).matches() || distanceRes) {
        distanceRes = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for distance restraints found.");
          }
        }
        if (DISTANCERES_PATTERN_2.matcher(line).matches()) {
          addDistanceRes(line, actualSection);
        } else if (isDataRow(line) && !DISTANCERES_PATTERN_1.matcher(line).matches()) {
          distanceRes = false;
        }
      }
      if (NONBONDPARAM_PATTERN_1.matcher(line).matches() || nonbondParams) {
        nonbondParams = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.STRUCTUREDATA);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for non bond params found.");
          }
        }
        if (NONBONDPARAM_PATTERN_2.matcher(line).matches()) {
          addNonbondParams(line);
        } else if (isDataRow(line) && !NONBONDPARAM_PATTERN_1.matcher(line).matches()) {
          nonbondParams = false;
        }
      }
      if (DIHEDRALSRES_PATTERN_1.matcher(line).matches() || dihedralsRes) {
        dihedralsRes = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.FORCEFIELD);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for dihedral restraints found.");
          }
        }
        if (DIHEDRALSRES_PATTERN_2.matcher(line).matches()) {
          addDihedralRes(line, actualSection);
        } else if (isDataRow(line) && !DIHEDRALSRES_PATTERN_1.matcher(line).matches()) {
          dihedralsRes = false;
        }
      }
      if (ORIENTATIONRES_PATTERN_1.matcher(line).matches() || orientationRes) {
        orientationRes = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.FORCEFIELD);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for orientation restraints found.");
          }
        }
        if (ORIENTATIONRES_PATTERN_2.matcher(line).matches()) {
          addOrientationRes(line, actualSection);
        } else if (isDataRow(line) && !ORIENTATIONRES_PATTERN_1.matcher(line).matches()) {
          orientationRes = false;
        }
      }
      if (ANGLERES_PATTERN_1.matcher(line).matches()
          || ANGLERESZ_PATTERN_1.matcher(line).matches()
          || angleRes) {
        angleRes = true;
        if (actualSection == null) {
          List<Section> sections = structure.getSections();
          if (!sections.isEmpty()) {
            actualSection = setSection(sections, SectionType.FORCEFIELD);
          }
          if (actualSection == null) {
            throw new RuntimeException("no valid Section for angle restraints found.");
          }
        }
        if (ANGLERES_PATTERN_2.matcher(line).matches()) {
          addAngleRes(line, actualSection);
        } else if (isDataRow(line)
            && (!ANGLERES_PATTERN_1.matcher(line).matches()
                || !ANGLERESZ_PATTERN_1.matcher(line).matches())) {
          angleRes = false;
        }
      }
    }
    if (arguments != null) {
      removeUnnecessaryData();
    }
  }