1 // ****************************************************************************** 2 // 3 // Title: Force Field X. 4 // Description: Force Field X - Software for Molecular Biophysics. 5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2025. 6 // 7 // This file is part of Force Field X. 8 // 9 // Force Field X is free software; you can redistribute it and/or modify it 10 // under the terms of the GNU General Public License version 3 as published by 11 // the Free Software Foundation. 12 // 13 // Force Field X is distributed in the hope that it will be useful, but WITHOUT 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 // details. 17 // 18 // You should have received a copy of the GNU General Public License along with 19 // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple 20 // Place, Suite 330, Boston, MA 02111-1307 USA 21 // 22 // Linking this library statically or dynamically with other modules is making a 23 // combined work based on this library. Thus, the terms and conditions of the 24 // GNU General Public License cover the whole combination. 25 // 26 // As a special exception, the copyright holders of this library give you 27 // permission to link this library with independent modules to produce an 28 // executable, regardless of the license terms of these independent modules, and 29 // to copy and distribute the resulting executable under terms of your choice, 30 // provided that you also meet, for each linked independent module, the terms 31 // and conditions of the license of that module. An independent module is a 32 // module which is not derived from or based on this library. If you modify this 33 // library, you may extend this exception to your version of the library, but 34 // you are not obligated to do so. If you do not wish to do so, delete this 35 // exception statement from your version. 36 // 37 // ****************************************************************************** 38 package ffx.realspace.parsers; 39 40 import ffx.potential.MolecularAssembly; 41 42 import java.io.File; 43 import java.io.IOException; 44 import java.nio.file.Path; 45 import java.nio.file.Paths; 46 import java.util.logging.Level; 47 import java.util.logging.Logger; 48 49 import static org.apache.commons.io.FilenameUtils.isExtension; 50 import static org.apache.commons.io.FilenameUtils.removeExtension; 51 52 /** 53 * RealSpaceFile class. 54 * 55 * @author Timothy D. Fenn 56 * @since 1.0 57 */ 58 public class RealSpaceFile { 59 60 private static final Logger logger = Logger.getLogger(RealSpaceFile.class.getName()); 61 62 private final String filename; 63 private final double weight; 64 private final RealSpaceFileFilter realSpaceFileFilter; 65 66 /** 67 * Read in a Real Space density file and set weight set to 1.0. 68 * 69 * @param filename file name to read in 70 */ 71 public RealSpaceFile(String filename) { 72 this(filename, 1.0); 73 } 74 75 /** 76 * Read in a Real Space density file. 77 * 78 * @param fileName file name to read in 79 * @param weight the weight of the data 80 */ 81 public RealSpaceFile(String fileName, double weight) { 82 File tmp = new File(fileName); 83 if (!tmp.exists()) { 84 logger.severe(" Data file: " + fileName + " not found!"); 85 } 86 87 if (isExtension(fileName, "map")) { 88 realSpaceFileFilter = new CCP4MapFilter(); 89 } else { 90 realSpaceFileFilter = null; 91 } 92 93 this.filename = fileName; 94 this.weight = weight; 95 } 96 97 /** 98 * Read in a Real Space density file based on the molecular assembly filename, using a weight of 99 * 1.0 and neutron value of false. 100 * 101 * @param assembly {@link ffx.potential.MolecularAssembly} from which a filename will be 102 * determined. 103 */ 104 public RealSpaceFile(MolecularAssembly[] assembly) { 105 this(assembly[0], 1.0); 106 } 107 108 /** 109 * Read in a Real Space density file based on the molecular assembly filename, using a weight of 110 * 1.0. 111 * 112 * @param assembly {@link ffx.potential.MolecularAssembly} from which a filename will be 113 * determined. 114 */ 115 public RealSpaceFile(MolecularAssembly assembly) { 116 this(assembly, 1.0); 117 } 118 119 /** 120 * Read in a Real Space density file based on the molecular assembly filename, using a weight of 121 * 1.0. 122 * 123 * @param assembly {@link ffx.potential.MolecularAssembly} from which a filename will be 124 * determined 125 * @param weight the weight of the data 126 */ 127 public RealSpaceFile(MolecularAssembly assembly, double weight) { 128 String name = removeExtension(assembly.getFile().getPath()); 129 130 File tmp = new File(name + ".map"); 131 if (tmp.exists()) { 132 logger.info(" Data file: " + tmp.getName()); 133 realSpaceFileFilter = new CCP4MapFilter(); 134 } else { 135 logger.severe(" No input data was found."); 136 realSpaceFileFilter = null; 137 } 138 139 String filenameHolder; 140 try { 141 Path filePath = Paths.get(tmp.getCanonicalPath()); 142 Path pwdPath = Paths.get(new File("").getCanonicalPath()); 143 filenameHolder = pwdPath.relativize(filePath).toString(); 144 } catch (IOException e) { 145 String message = 146 " Relative path to provided data file could not be resolved: using map file name instead."; 147 logger.log(Level.WARNING, message, e); 148 filenameHolder = tmp.getName(); 149 } 150 this.filename = filenameHolder; 151 this.weight = weight; 152 } 153 154 /** 155 * Getter for the field <code>filename</code>. 156 * 157 * @return the filename 158 */ 159 public String getFilename() { 160 return filename; 161 } 162 163 /** 164 * Getter for the field <code>realSpaceFileFilter</code>. 165 * 166 * @return the realSpaceFileFilter 167 */ 168 public RealSpaceFileFilter getRealSpaceFileFilter() { 169 return realSpaceFileFilter; 170 } 171 172 /** 173 * Return the weight of this dataset. 174 * 175 * @return weight The weight (wA). 176 */ 177 public double getWeight() { 178 return weight; 179 } 180 }