$darkmode
DENOPTIM
MMBuilderUtils.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.molecularmodeling;
21
22import java.io.BufferedReader;
23import java.io.FileReader;
24import java.io.IOException;
25import java.util.ArrayList;
26
27import denoptim.exception.DENOPTIMException;
28
29
36public class MMBuilderUtils
37{
38
39//------------------------------------------------------------------------------
40
48 public static void readKeyFileParams(String filename, ArrayList<String> data)
50 {
51 BufferedReader br = null;
52 String line;
53
54 try
55 {
56 br = new BufferedReader(new FileReader(filename));
57 while ((line = br.readLine()) != null)
58 {
59 line = line.trim();
60 data.add(line);
61 }
62 }
63 catch (IOException nfe)
64 {
65 throw new DENOPTIMException(nfe);
66 }
67 finally
68 {
69 try
70 {
71 if (br != null)
72 {
73 br.close();
74 }
75 }
76 catch (IOException ioe)
77 {
78 throw new DENOPTIMException(ioe);
79 }
80 }
81
82 if (data.isEmpty())
83 {
84 String msg = "No data found in file: " + filename;
85 throw new DENOPTIMException(msg);
86 }
87 }
88
89//------------------------------------------------------------------------------
90
99 public static int countLinesWKeywordInFile(String filename, String keyword)
100 throws DENOPTIMException
101 {
102
103 BufferedReader br = null;
104 String line;
105
106 try
107 {
108 int count = 0;
109 br = new BufferedReader(new FileReader(filename));
110
111 while ((line = br.readLine()) != null)
112 {
113 if (line.startsWith(keyword))
114 {
115 count++;
116 }
117 }
118 return count;
119 }
120 catch (IOException ioe)
121 {
122 throw new DENOPTIMException(ioe);
123 }
124 finally
125 {
126 try
127 {
128 if (br != null)
129 {
130 br.close();
131 }
132 }
133 catch (IOException ioe)
134 {
135 throw new DENOPTIMException(ioe);
136 }
137 }
138 }
139
140//------------------------------------------------------------------------------
141}
Utilities for molecular models builder.
static int countLinesWKeywordInFile(String filename, String keyword)
Count the number of lines starting with a keyword.
static void readKeyFileParams(String filename, ArrayList< String > data)
Read the parameter settings to be used by PSSROT.