crystalcell 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.1.3"
11
+ gem "jeweler", "~> 1.8.3"
12
+ gem "simplecov", ">= 0"
13
+ gem "mageo", ">= 0.0.0"
14
+ gem "malge", ">= 0.0.1"
15
+ gem "maset", ">= 0.0.0"
16
+ gem "builtinextension", ">= 0.0.3"
17
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 ippei94da
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = crystalcell
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to crystalcell
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 ippei94da. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "crystalcell"
18
+ gem.homepage = "http://github.com/ippei94da/crystalcell"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Classes around a cell in crystallography}
21
+ gem.description = %Q{This gem provides Cell, LatticeAxes, Atom classes, and so on.
22
+ And this provides simple treatment of a periodic boundary condition.
23
+ }
24
+ gem.email = "ippei94da@gmail.com"
25
+ gem.authors = ["ippei94da"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ #require 'rcov/rcovtask'
38
+ #Rcov::RcovTask.new do |test|
39
+ # test.libs << 'test'
40
+ # test.pattern = 'test/**/test_*.rb'
41
+ # test.verbose = true
42
+ # test.rcov_opts << '--exclude "gems/*"'
43
+ #end
44
+
45
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "crystalcell #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,133 @@
1
+
2
+ raise "Atom class need ruby version later than 1.9." if RUBY_VERSION.to_f < 1.9
3
+
4
+
5
+ require "rubygems"
6
+ gem "mageo"
7
+ require "mageo/vector3dinternal.rb"
8
+
9
+ # Class for an atom in a cell.
10
+ # This class doesn't have lattice information.
11
+ # Forbid changes in internal information. When you want to change, you can make a new instance.
12
+ # This class is not assumeed in a periodic condition.
13
+ class Atom
14
+ class TypeError < Exception ; end
15
+
16
+ # Do not change :position to attr_accessor.
17
+ # This must be Vector3DInternal instance.
18
+ attr_reader :movable_flags
19
+ attr_accessor :element, :name, :position
20
+
21
+ # Arguments:
22
+ # elements:
23
+ # Identifier of a element.
24
+ # This may be String like "Li", Integer like 0, or other class instances.
25
+ # Why doesn't this class have concrete name of elements?
26
+ # The reason is below:
27
+ # - This class is assumed to be used in Cell class instances.
28
+ # When we treat symmetry of the cell, the elements of atoms are not necessary information.
29
+ # This specification enable highly abstract level of treatment of cells.
30
+ # - POSCAR file of VASP (before ver.4 series) don't have element information.
31
+ # This specification enable to use POSCAR directly without POTCAR or element indication.
32
+ # position:
33
+ # Coordinates of an atom.
34
+ # This argument 'position' is mainly assumed as a internal coordinate.
35
+ # name:
36
+ # Identifier of an atom, e.g., "Li1" or "O23".
37
+ # movable_flags:
38
+ # Movable flags of an atom in each of three directions as a Array of three items.
39
+ def initialize(element, position, name = nil, movable_flags = nil)
40
+ #p position
41
+ #p position.methods.sort
42
+ raise TypeError, "Position doesn't have []: (#{position.inspect})" unless position.methods.include?(:[])
43
+ raise TypeError, "Number of items in position is not 3: (#{position})" if position.size != 3
44
+ raise TypeError, "Coordinate is not a Float: (#{position})" if position[0].class != Float
45
+ raise TypeError, "Coordinate is not a Float: (#{position})" if position[1].class != Float
46
+ raise TypeError, "Coordinate is not a Float: (#{position})" if position[2].class != Float
47
+
48
+ @element = element
49
+ set_position(position)
50
+ @name = name
51
+ @movable_flags = movable_flags
52
+ end
53
+
54
+ ## Class methods
55
+
56
+ # Equivalence checking (class method version).
57
+ # Return true when all the condition below are satisfied:
58
+ # - same element identifier.
59
+ # - difference of coordinates is within tolerance.
60
+ # Note that distance cannot be used since this class doesn't have a lattice axes.
61
+ # Imagine the shape of tolerant zone is a hexahedron.
62
+ def self.equal_in_delta?(atom0, atom1, tol = 0.0)
63
+ return false if atom0.element != atom1.element
64
+ 3.times do |i|
65
+ return false if ((atom0.position[i] - atom1.position[i]).abs > tol)
66
+ end
67
+ return true
68
+ end
69
+
70
+ ## Instance methods
71
+
72
+ # Restricted equivalence checking.
73
+ # Return true when all the condition below are satisfied:
74
+ # - same element identifier.
75
+ # - difference of coordinates is the same.
76
+ # This method should be used after well-consideration.
77
+ # Arbitrary coordinates are not generally the same like Float instances.
78
+ # It is a good idea to use in test scripts.
79
+ def ==(other)
80
+ #pp self
81
+ #pp other
82
+ self.class.equal_in_delta?(self, other, 0.0)
83
+ end
84
+
85
+ # Equivalence checking (instance method version) .
86
+ # Return true when all the condition below are satisfied:
87
+ # - same element identifier.
88
+ # - difference of coordinates is within tolerance.
89
+ def equal_in_delta?(other, tol = 0.0)
90
+ self.class.equal_in_delta?(self, other, tol)
91
+ end
92
+
93
+ #Return Vector3DInternal instance consist of coordinates between 0 and 1.
94
+ def internal_coordinates
95
+ result = @position.map{ |coord| coord - coord.floor }
96
+ return Vector3DInternal[ *result ]
97
+ end
98
+
99
+ # Return Vector3DInternal instance consist of integers,
100
+ # by which self.internal_coordinates translate to self.position.
101
+ def translation_symmetry_operation
102
+ result = @position.map{ |coord| coord.floor }
103
+ return Vector3DInternal[ *result ]
104
+ end
105
+
106
+ # Overwrite position.
107
+ def set_position(position)
108
+ #pp position
109
+ #pp position.class
110
+ raise TypeError, "#{position.class}" if position.class == Vector3D
111
+ @position = position.to_v3di
112
+ end
113
+
114
+ # Translate atom position (destructive).
115
+ # Argument 'vec' should be given as internal vector,
116
+ # which is an Array or Vector3DInternal instance but Vector3D instance.
117
+ def translate!(vec)
118
+ raise TypeError if vec.class == Vector3D
119
+ raise TypeError if vec.size != 3
120
+ self.set_position(@position + Vector3DInternal[ *vec ])
121
+ end
122
+
123
+ # Translate atom position (nondestructive).
124
+ # Argument 'vec' should be given as internal vector,
125
+ # which is an Array or Vector3DInternal instance but Vector3D instance.
126
+ def translate(vec)
127
+ tmp = Marshal.load(Marshal.dump(self))
128
+ tmp.translate!(vec)
129
+ return tmp
130
+ end
131
+
132
+ end
133
+