19package denoptim.graph.rings;
21import java.io.BufferedReader;
23import java.io.FileInputStream;
24import java.io.FileOutputStream;
25import java.io.FileReader;
26import java.io.IOException;
27import java.io.ObjectInputStream;
28import java.io.ObjectOutputStream;
29import java.io.RandomAccessFile;
30import java.nio.channels.FileChannel;
31import java.nio.channels.FileLock;
32import java.nio.channels.OverlappingFileLockException;
33import java.util.ArrayList;
34import java.util.HashMap;
35import java.util.logging.Level;
37import denoptim.exception.DENOPTIMException;
38import denoptim.files.FileUtils;
75 private HashMap<Integer,ArrayList<ClosableChain>>
libCCxTPIdx =
110 BufferedReader br =
null;
114 br =
new BufferedReader(
new FileReader(filename));
115 while ((line = br.readLine()) !=
null)
117 if (line.trim().length() == 0)
122 String[] parts = line.trim().split(
"\\s+");
123 String chainIdStr = parts[0];
124 String rccIdNum = parts[1];
125 String closability = parts[2];
127 if (Integer.parseInt(rccIdNum) !=
nextRccId)
129 String msg =
"Expecting RCC Ids to be ordered (i.e., "
130 +
"1,2,3,...,n), but inconsistent number "
131 +
"is found in " + filename +
" - Found"
138 String msg =
"Found duplicate in library of RCCs";
142 addRecord(chainIdStr,rccIdNum,closability);
145 catch (NumberFormatException | IOException nfe)
158 catch (IOException ioe)
166 String err =
"No entry taken from RCC index file: ";
177 ArrayList<String> record =
new ArrayList<String>();
178 record.add(rccIdNum);
179 record.add(closability);
185 if (closability.equals(
"T"))
198 ArrayList<ClosableChain> lstCC =
new ArrayList<ClosableChain>();
221 String closability =
"F";
228 long fileLength = file.length();
229 RandomAccessFile rafile =
null;
230 FileChannel channel =
null;
231 FileLock lock =
null;
235 rafile =
new RandomAccessFile(file,
"rw");
236 channel = rafile.getChannel();
243 lock = channel.tryLock();
247 catch (OverlappingFileLockException e)
251 +
" to get lock " +
"for '"
260 +
" RingClosingConformations");
264 String rccId = Integer.toString(
nextRccId);
270 rafile.seek(fileLength);
271 rafile.writeBytes(chainId +
" " + rccId +
" " +
"T" +
"\n");
276 +
"/" + rccId +
".ser";
277 FileOutputStream fos =
null;
278 ObjectOutputStream oos =
null;
281 fos =
new FileOutputStream(rccFileName);
282 oos =
new ObjectOutputStream(fos);
283 oos.writeObject(rcc);
286 "Serialization to file " + rccFileName);
302 rafile.seek(fileLength);
303 rafile.writeBytes(chainId +
" " + rccId +
" " +
"F" +
"\n");
309 throw new IllegalStateException(
"Exception while trying to store "
320 if (lock !=
null && lock.isValid())
325 throw new IllegalStateException(
"RingClosuresArchive is unable "
348 return new ArrayList<ClosableChain>();
383 String closability = rccRecord.get(1);
384 return closability.equals(
"T");
397 int rccId = Integer.parseInt(rccRecord.get(0));
398 String closability = rccRecord.get(1);
401 if (closability.equals(
"T"))
407 "Path is closable (from DB)");
415 "Path is NOT closable (from DB)");
434 System.getProperty(
"file.separator") + rccId +
".ser";
435 FileInputStream fis =
null;
436 ObjectInputStream ois =
null;
437 boolean recoveringDone =
false;
440 fis =
new FileInputStream(rccFileName1);
441 ois =
new ObjectInputStream(fis);
445 "Got serialized RCC from " + rccFileName1);
446 recoveringDone =
true;
450 throw new IllegalStateException(t2);
460 throw new IllegalStateException(t);
465 String s =
"Failed attempt to recover RCC. Check code.";
466 throw new IllegalStateException(s);
static boolean checkExists(String fileName)
ClosableChain represents a chain of fragments (chain links) that is closable (or candidate closable).
int getTurningPointIdx()
Get the vertex ID of the turning point.Note that since the chain is a path in a graph the relative di...
This object represents a path in a DGraph.
List< String > getAllAlternativeChainIDs()
Returns all the possible IDs for this chain.
Parameters and setting related to handling ring closures.
int getVerbosity()
Returns the level of verbosity, i.e., the amount of log that we want to print.
boolean serializeRCCs
FLag controlling the serialization of the RingClosingConformations.
String getRCCLibraryFolder()
String getRCCLibraryIndexFile()
Data structure to store and handle information about sub-structures (i.e., chains of fragments) and r...
void addRecord(String chainId, String rccIdNum, String closability)
RingClosingConformations getRCCsOfChain(String chainId)
void storeEntry(String chainId, boolean closable, RingClosingConformations rcc)
Append a new closable chain entry to the archive.
HashMap< Integer, ArrayList< ClosableChain > > libCCxTPIdx
Data structure containing the library of ClosableChains per each fragment that can act as a turning p...
int nextRccId
Index of the next entry to be added to the archive.
boolean getClosabilityOfChain(String chainId)
RingClosuresArchive()
Construct an empty archive.
RingClosingConformations getRCCsFromArchive(int rccId)
Get serialized RingClosingConformations from archive.
RingClosuresArchive(RingClosureParameters settings)
Construct the library of ring closing substructures from an existing index file.
String containsChain(PathSubGraph chain)
ArrayList< ClosableChain > getCCFromTurningPointId(int tpId)
Returns the library of closable chains having the given turning point (i.e., the fragments involved i...
RingClosureParameters settings
Parameters.
HashMap< String, ArrayList< String > > rccsPerChainId
Data structure containing the main information about the RingClosingConformations (values) per each C...
void readLibraryOfRCCs(String filename)
Logger getLogger()
Get the name of the program specific logger.