// 复制文件
//将PDB文件中的ATOM重新标定位置
public static void junhSpeCopyPDBFile(File sourceFile, File targetFile) throws Exception {
String targetFilePath = targetFile.getParent();
File targetParentFile = new File(targetFilePath);
if(!targetParentFile.exists()){
targetParentFile.mkdirs();
}
String firstChain = "JunHu2012-12-26";
//得到第一ChainType
BufferedReader srcBr = new BufferedReader(new FileReader(sourceFile));
String line = srcBr.readLine();
while (null != line){
if (line.startsWith("ATOM")) {
String chainType = line.substring(21, 22);
if (!chainType.equalsIgnoreCase(firstChain)) {
String atomType = line.substring(11, 15).trim();
if (atomType.equalsIgnoreCase("CA")) {
firstChain = chainType;
break;
}
}
}
line = srcBr.readLine();
}
srcBr.close();
FileWriter fw = new FileWriter(targetFile);
String preIndexStr = "YanDanDan2012-12-26";
int preIndexInt = 0;
//重新标定First ChainType
srcBr = new BufferedReader(new FileReader(sourceFile));
line = srcBr.readLine();
while (null != line){
if (line.startsWith("ATOM")) {
String acidType = line.substring(17, 20);
if (3 == acidType.trim().length()){
String chainType = line.substring(21, 22);
if (chainType.equalsIgnoreCase(firstChain)) {
String preLine = line.substring(0, 22);
String IndexStr = line.substring(22, 26);
String afterLine = line.substring(26);
if (IndexStr.equals(preIndexStr)){
fw.write(preLine + StrUtil.formatStrToFixLen(Integer.toString(preIndexInt), 26-22) + afterLine + "\n");
}else{
fw.write(preLine + StrUtil.formatStrToFixLen(Integer.toString(++preIndexInt), 26-22) + afterLine + "\n");
preIndexStr = IndexStr;
}
}
}
}
line = srcBr.readLine();
}
srcBr.close();
fw.close();
}
//将PDB文件中的ATOM重新标定位置
public static void junhSpeCopyPDBFile(File sourceFile, File targetFile) throws Exception {
String targetFilePath = targetFile.getParent();
File targetParentFile = new File(targetFilePath);
if(!targetParentFile.exists()){
targetParentFile.mkdirs();
}
String firstChain = "JunHu2012-12-26";
//得到第一ChainType
BufferedReader srcBr = new BufferedReader(new FileReader(sourceFile));
String line = srcBr.readLine();
while (null != line){
if (line.startsWith("ATOM")) {
String chainType = line.substring(21, 22);
if (!chainType.equalsIgnoreCase(firstChain)) {
String atomType = line.substring(11, 15).trim();
if (atomType.equalsIgnoreCase("CA")) {
firstChain = chainType;
break;
}
}
}
line = srcBr.readLine();
}
srcBr.close();
FileWriter fw = new FileWriter(targetFile);
String preIndexStr = "YanDanDan2012-12-26";
int preIndexInt = 0;
//重新标定First ChainType
srcBr = new BufferedReader(new FileReader(sourceFile));
line = srcBr.readLine();
while (null != line){
if (line.startsWith("ATOM")) {
String acidType = line.substring(17, 20);
if (3 == acidType.trim().length()){
String chainType = line.substring(21, 22);
if (chainType.equalsIgnoreCase(firstChain)) {
String preLine = line.substring(0, 22);
String IndexStr = line.substring(22, 26);
String afterLine = line.substring(26);
if (IndexStr.equals(preIndexStr)){
fw.write(preLine + StrUtil.formatStrToFixLen(Integer.toString(preIndexInt), 26-22) + afterLine + "\n");
}else{
fw.write(preLine + StrUtil.formatStrToFixLen(Integer.toString(++preIndexInt), 26-22) + afterLine + "\n");
preIndexStr = IndexStr;
}
}
}
}
line = srcBr.readLine();
}
srcBr.close();
fw.close();
}