-
Hyun Soo Kim authoredHyun Soo Kim authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ProteinFactory.java 8.97 KiB
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
public class ProteinFactory {
private static ProteinFactory INSTANCE;
private ProteinFactory() throws IOException {
}
public static ProteinFactory getInstance() throws IOException {
if (INSTANCE == null) {
INSTANCE = new ProteinFactory();
}
return INSTANCE;
}
static Random rng = new Random();
static final AminoAcid ALANINE;
static final AminoAcid GLYCINE;
static {
try {
ALANINE = new AminoAcid("testcases/amino_acid/Alanine.txt",
2, 12, 10, 5, 4);
GLYCINE = new AminoAcid("testcases/amino_acid/Glycine.txt",
1, 9, 7, 4, 3);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static public class AminoAcid {
int atomCount;
StringBuffer atomBuffer;
int bondCount = 0;
ArrayList<Integer> bondList = new ArrayList<>();
String name;
ArrayList<Integer> termini = new ArrayList<>();
int terminusC;
int terminusHN;
int terminusHO;
int terminusN;
int terminusO;
public AminoAcid(
String filePath, int terminusC, int terminusHN, int terminusHO, int terminusN, int terminusO)
throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
name = reader.readLine();
atomCount = Integer.parseInt(reader.readLine());
atomBuffer = new StringBuffer(atomCount);
for (int atomIdx = 0; atomIdx < atomCount; atomIdx++) {
atomBuffer.append(reader.readLine());
}
String bond;
while ((bond = reader.readLine()) != null) {
String[] atoms = bond.split(" ");
bondList.add(Integer.parseInt(atoms[0]));
bondList.add(Integer.parseInt(atoms[1]));
bondCount++;
}
}
termini.add(terminusHN);
termini.add(terminusHO);
termini.add(terminusO);
termini.sort(null);