コード例 #1
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addAngleType(String line) {
   List<Angle> angleTypes = structure.getAngleTypes();
   List<String> split = reworkLine(line);
   int length = split.size();
   AngleImpl a = new AngleImpl();
   if (length >= 6) {
     a.setAi(split.get(0));
     a.setAj(split.get(1));
     a.setAk(split.get(2));
     a.setFuncType(Integer.parseInt(split.get(3)));
     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 < 6 || length > 10) {
     ch.printErrorln(String.format("some ANGLETYPES values are lost! --> %s", line));
   } else {
     angleTypes.add(a);
   }
 }
コード例 #2
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addBondType(String line) {
   List<String> split = reworkLine(line);
   List<Bond> bondTypes = structure.getBondTypes();
   int length = split.size();
   BondImpl bt = new BondImpl();
   if (length >= 3) {
     bt.setAi(split.get(0));
     bt.setAj(split.get(1));
     bt.setFuncType(Integer.parseInt(split.get(2)));
   }
   if (length >= 5) {
     bt.setC1(new BigDecimal(split.get(3)));
     bt.setC2(new BigDecimal(split.get(4)));
   }
   if (length >= 6) {
     bt.setC3(new BigDecimal(split.get(5)));
   }
   if (length >= 7) {
     bt.setC4(new BigDecimal(split.get(6)));
   }
   if (length < 3 || length > 7) {
     ch.printErrorln(String.format("some BONDTYPES values are lost! --> %s", line));
   } else {
     bondTypes.add(bt);
   }
 }
コード例 #3
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addPairType(String line) {
   List<String> split = reworkLine(line);
   List<Pair> pairTypes = structure.getPairTypes();
   PairImpl pt = new PairImpl();
   int length = split.size();
   if (length >= 3) {
     pt.setAi(split.get(0));
     pt.setAj(split.get(1));
     pt.setFuncType(Integer.parseInt(split.get(2)));
   }
   if (length >= 5) {
     pt.setC1(new BigDecimal(split.get(3)));
     pt.setC2(new BigDecimal(split.get(4)));
   }
   if (length >= 7) {
     pt.setC3(new BigDecimal(split.get(5)));
     pt.setC4(new BigDecimal(split.get(6)));
   }
   if (length == 8) {
     pt.setC5(new BigDecimal(split.get(7)));
   }
   if (length < 3 || length > 8) {
     ch.printErrorln(String.format("some PAIRTYPES values are lost! --> %s", line));
   } else {
     pairTypes.add(pt);
   }
 }
コード例 #4
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addAtomType(String line) {
   List<String> split = reworkLine(line);
   // TODO replace when atom atom translation dictionary exists --> special handling of oplsaa FF
   // produces errors if oplsaa is used
   if (split.size() == 8) {
     String s = split.get(0);
     String s1 = split.get(1);
     split.remove(0);
     split.remove(0);
     split.add(0, s + " " + s1);
   }
   if (split.size() == 7) {
     List<AtomType> atomTypes = structure.getAtomTypes();
     AtomTypeImpl at = new AtomTypeImpl();
     at.setName(split.get(0));
     at.setNum(split.get(1));
     at.setC1(new BigDecimal(split.get(2)));
     at.setC2(new BigDecimal(split.get(3)));
     at.setParticleType(split.get(4));
     at.setC3(new BigDecimal(split.get(5)));
     at.setC4(new BigDecimal(split.get(6)));
     atomTypes.add(at);
   } else {
     ch.printErrorln(String.format("some ATOMTYPES values are lost! --> %s", line));
   }
 }
コード例 #5
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addHeader(String line) {
   if (line.length() >= 3) {
     List<String> headers = structure.getHeaderComments();
     headers.add(line.substring(2, line.length()));
   } else {
     ch.printErrorln(String.format("some HEADERS values are lost! --> %s", line));
   }
 }
コード例 #6
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addDefault(String line) {
   List<String> split = reworkLine(line);
   if (split.size() == 5) {
     DefaultImpl def = new DefaultImpl();
     def.setNboudnFT(Integer.parseInt(split.get(0)));
     def.setCombRule(Integer.parseInt(split.get(1)));
     def.setGenPair(split.get(2).equals("yes"));
     def.setC1(new BigDecimal(split.get(3)));
     def.setC2(new BigDecimal(split.get(4)));
     structure.setDef(def);
   } else {
     ch.printErrorln(String.format("some DEFAULTS 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 addGenbornParam(String line) {
   List<String> split = reworkLine(line);
   if (split.size() == 6) {
     List<ImplicitGenbornParam> genbornParams = structure.getGenbornParams();
     ImplicitGenbornParamImpl gp = new ImplicitGenbornParamImpl();
     gp.setAtom(split.get(0));
     gp.setC1(new BigDecimal(split.get(1)));
     gp.setC2(new BigDecimal(split.get(2)));
     gp.setC3(new BigDecimal(split.get(3)));
     gp.setC4(new BigDecimal(split.get(4)));
     gp.setC5(new BigDecimal(split.get(5)));
     genbornParams.add(gp);
   } else {
     ch.printErrorln(String.format("some GENBORN values are lost! --> %s", line));
   }
 }
コード例 #9
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addConstraintType(String line) {
   List<String> split = reworkLine(line);
   List<Constraint> constraintTypes = structure.getConstraintTypes();
   ConstraintImpl ct = new ConstraintImpl();
   int length = split.size();
   if (length >= 4) {
     ct.setAi(split.get(0));
     ct.setAj(split.get(1));
     ct.setFuncType(Integer.parseInt(split.get(2)));
     ct.setC1(new BigDecimal(split.get(3)));
   }
   if (length == 5) {
     ct.setC2(new BigDecimal(split.get(4)));
   }
   if (length < 4 || length > 5) {
     ch.printErrorln(String.format("some CONSTRAINTTYPES values are lost! --> %s", line));
   } else {
     constraintTypes.add(ct);
   }
 }
コード例 #10
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addNonbondParams(String line) {
   List<String> split = reworkLine(line);
   List<NonBondParam> nonbondRes = structure.getNonBondParams();
   int length = split.size();
   NonBondParamImpl param = new NonBondParamImpl();
   if (length >= 5) {
     param.setAi(split.get(0));
     param.setAj(split.get(1));
     param.setFuncType(Integer.parseInt(split.get(2)));
     param.setC1(new BigDecimal(split.get(3)));
     param.setC2(new BigDecimal(split.get(4)));
   }
   if (length >= 6) {
     param.setC3(new BigDecimal(split.get(5)));
   }
   if (length < 5 || length > 6) {
     ch.printErrorln(String.format("some nonbond params values are lost! --> %s", line));
   } else {
     nonbondRes.add(param);
   }
 }
コード例 #11
0
ファイル: InputParser.java プロジェクト: ccaleman/MDConverter
 private void addDihedralType(String line) {
   List<Dihedral> dihedralTypes = structure.getDihedralTypes();
   List<String> split = reworkLine(line);
   DihedralImpl dt = new DihedralImpl();
   int length = split.size();
   if (length == 6) {
     dt.setAi(split.get(0));
     dt.setAj(split.get(1));
     dt.setFuncType(Integer.parseInt(split.get(2)));
     dt.setC1(new BigDecimal(split.get(3)));
     dt.setC2(new BigDecimal(split.get(4)));
     dt.setC3(new BigDecimal(split.get(5)));
   } else if (length >= 7) {
     dt.setAi(split.get(0));
     dt.setAj(split.get(1));
     dt.setAk(split.get(2));
     dt.setAl(split.get(3));
     dt.setFuncType(Integer.parseInt(split.get(4)));
     dt.setC1(new BigDecimal(split.get(5)));
     dt.setC2(new BigDecimal(split.get(6)));
   }
   if (length >= 8) {
     dt.setC3(new BigDecimal(split.get(7)));
   }
   if (length >= 9) {
     dt.setC4(new BigDecimal(split.get(8)));
   }
   if (length >= 10) {
     dt.setC5(new BigDecimal(split.get(9)));
   }
   if (length == 11) {
     dt.setC6(new BigDecimal(split.get(10)));
   }
   if (length < 6 || length > 11) {
     ch.printErrorln(String.format("some DIHEDRALTYPES values are lost! --> %s", line));
   } else {
     dihedralTypes.add(dt);
   }
 }
コード例 #12
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();
    }
  }