1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package ffx.xray.commands;
39
40 import ffx.algorithms.cli.AlgorithmsCommand;
41 import ffx.crystal.Crystal;
42 import ffx.crystal.ReflectionList;
43 import ffx.crystal.Resolution;
44 import ffx.numerics.Potential;
45 import ffx.potential.MolecularAssembly;
46 import ffx.utilities.FFXBinding;
47 import ffx.xray.DiffractionRefinementData;
48 import ffx.xray.parsers.CIFFilter;
49 import ffx.xray.parsers.MTZWriter;
50 import ffx.xray.parsers.MTZWriter.MTZType;
51 import picocli.CommandLine.Command;
52 import picocli.CommandLine.Parameters;
53
54 import java.io.File;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.List;
58 import java.util.stream.Collectors;
59
60 import static org.apache.commons.io.FilenameUtils.removeExtension;
61
62
63
64
65
66
67
68
69 @Command(description = " Convert a CIF file to MTZ format.", name = "xray.CIFtoMTZ")
70 public class CIFtoMTZ extends AlgorithmsCommand {
71
72
73
74
75 @Parameters(arity = "2", paramLabel = "file", description = "A PDB file and a CIF diffraction file.")
76 private List<String> filenames = null;
77
78 private MolecularAssembly[] molecularAssemblies;
79 private DiffractionRefinementData refinementData;
80
81
82
83
84 public CIFtoMTZ() {
85 super();
86 }
87
88
89
90
91
92 public CIFtoMTZ(String[] args) {
93 super(args);
94 }
95
96
97
98
99
100 public CIFtoMTZ(FFXBinding binding) {
101 super(binding);
102 }
103
104
105
106
107 @Override
108 public CIFtoMTZ run() {
109
110 if (!init()) {
111 return this;
112 }
113
114 String pdb = filenames.get(0);
115 String cif = filenames.get(1);
116
117 logger.info("\n Running CIF2MTZ on " + cif);
118
119
120 molecularAssemblies = algorithmFunctions.openAll(pdb);
121
122 CIFFilter cifFilter = new CIFFilter();
123 ReflectionList reflectionlist =
124 cifFilter.getReflectionList(new File(cif), molecularAssemblies[0].getProperties());
125
126 if (reflectionlist == null) {
127 System.out.println(" Using crystal information from the PDB file to generate MTZ file.");
128
129 Crystal crystal = molecularAssemblies[0].getCrystal().getUnitCell();
130 double res = cifFilter.getResolution(new File(cif), crystal);
131 if (res < 0.0) {
132 System.out.println(" Resolution could not be determined from the PDB and CIF files.");
133 return this;
134 }
135
136 Resolution resolution = new Resolution(res);
137 reflectionlist = new ReflectionList(crystal, resolution,
138 molecularAssemblies[0].getProperties());
139 }
140
141 refinementData = new DiffractionRefinementData(molecularAssemblies[0].getProperties(),
142 reflectionlist);
143 cifFilter.readFile(new File(cif), reflectionlist, refinementData,
144 molecularAssemblies[0].getProperties());
145
146 MTZWriter mtzwriter = new MTZWriter(reflectionlist, refinementData,
147 removeExtension(cif) + ".mtz", MTZType.DATAONLY);
148 mtzwriter.write();
149
150 return this;
151 }
152
153 @Override
154 public List<Potential> getPotentials() {
155 if (molecularAssemblies == null) {
156 return new ArrayList<>();
157 } else {
158 return Arrays.stream(molecularAssemblies)
159 .filter(a -> a != null)
160 .map(a -> a.getPotentialEnergy())
161 .filter(e -> e != null)
162 .collect(Collectors.toList());
163 }
164 }
165 }